PythonPath / sys.path

Barry barry at barrys-emacs.org
Sun May 14 12:43:43 EDT 2023



> On 14 May 2023, at 16:32, Grizzy Adams via Python-list <python-list at python.org> wrote:
> 
> Hi All
> 
> My first post (repeated)
> 
> I am having a problem with PythonPath / sys.path
> 
> I have a dir where I keep all my current work, but I can't seem to add it to 
> PythonPath / sys.path
> 
> When I try to import one of my modules I see
> 
>>>> import My_Working_File
> Traceback (most recent call last):
>  File "<pyshell#0>", line 1, in <module>
>    import My_Working_File
> ImportError: No module named 'My_Working_File'
> 
> I have tried adding my dir in registry to the existing PythonPath 
> 
> [HKEY_CURRENT_USER\Software\Python\PythonCore\3.4\PythonPath]
> @="D:\\Shades\\Tools\\Python\\Lib;D:\\Shades\\Tools\\Python\\DLLs"
> 
> that did not help, 
> 
> I tried adding PYTHONPATH as an enviramental variable, that also had no effect
> 
> (I did re-boot after these two tests)
> 
> If I go to the editor window and run (F5) any of my modules then I can 
> 
>>>> ================================ RESTART ================================
>>>> 
>>>> import My_Working_File
>>>> 
> 
> without error
> 
> I can also (from a fresh start) 
> 
>>>> import sys
>>>> sys.path.append(r'D:\Shades\Tools\Python\MyWork')
>>>> print(sys.path)
> ['', 'D:\\Shades\\Tools\\Python\\Lib\\idlelib', 
> 'D:\\Shades\\Tools\\Python\\python34.zip', 'D:\\Shades\\Tools\\Python\\DLLs', 
> 'D:\\Shades\\Tools\\Python\\lib', 'D:\\Shades\\Tools\\Python', 
> 'D:\\Shades\\Tools\\Python\\lib\\site-packages', 
> 'D:\\Shades\\Tools\\Python\\MyWork']
>>>> import My_Working_File
>>>> 
> 
> I don't really want to go this route every time I start work, and more to the 
> point I will need (to learn how) to add dir's to the path at times
> 
> I did search the net for an answer but only got what I had already tried
> 
> any pointers what I'm doing wrong (other than using windows '->) 

I take it you have business reasons to use an obsolete version python.
Where did you get your version of python from?

You seem to be doing the right thing with setting an environment variable.
Useless shades is an app that embeds python.

Try starting cmd.exe and using the set command to liat all of the environment.
Do you see your PYTHONPATH variable?
Does it contain what you expect?
If it does start python and check that sys.path has your folder in it.
Also check what is on os.environ dirctionary.

Barry
> 
> Grizz
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 



More information about the Python-list mailing list