How to edit PYTHONPATH on Windows

How to edit PYTHONPATH on WindowsDalya GartzmanBlockedUnblockFollowFollowingMay 14You are here because you are using:Windows OS version 10+Python version 3.

3+Anaconda3And you would like to edit your PYTHONPATH permanently.

TL;DRGo to C:Users<your_username>Anaconda3Libsite-packagesCreate a file python37.

pthEdit the file to include this line C:Users<your_username>my_moduleThe Long version; Do ReadPrologueIn most cases, editing the PYTHONPATH from the Settings GUI will do the trick.

The trick is well explained in this Stack Overflow answer.

If in the first place you are only looking to edit your path locally, this helpful answer will do.

Slightly Extended Item no.

 1If you don’t have C:Users<your_username>Anaconda3Libsite-packages, replace C:Users<your_username> with the path to your Anaconda3.

Slightly Extended Item no.

 2If you are using Python3.

7, create a file called python37.


Else create a file called python<XX>.

pth for whatever Python version you are using.

Not sure which version? Under C:Users<your_username>Anaconda3 search for a file of the form python<XX>.


The <XX> indicates the version number you need for naming your .

pth file.

Windows is super annoying and won’t let you create a file with a .

pth suffix? There are such files in the C:Users<your_username>Anaconda3Libsite-packages folder.

Copy one of them and edit the prefix.

Some places say you need to create a .

_pth file instead of .

pth?A .

_pth file will completely replace your existing path.

While a .

pth file will append its content to the path you already have.

You can find more information here.

Slightly Extended Item no.

 3Assuming the SuperCoolClass you wish to import is located at C:Users<your_username>my_project_foldermy_awesome_file.

py .

Then open your newly created python<XX>.

pth file with your favorite text editor (please don’t say it’s Vim) and add one line:C:Users<your_username>my_project_folder.

Yes, with those annoying double slashes  .

No, without quotes "" .

And that’s it.

Now you can import from anywhere, like a normal person:from my_awesome_file import SuperCoolClass .

EpilogueNothing important to add here really.

 I just hope my 2 hours of frustration + 1 hour of writing this post saved you some time.

Peace out.


. More details

Leave a Reply