Sådan redigeres PYTHONPATH på Windows

Du er her, fordi du bruger:

  1. Windows OS version 10+
  2. Python version 3.3+
  3. Anaconda3

Og du vil gerne redigere din PYTHONPATHpermanent.


  1. Gå til C:\Users\\Anaconda3\Lib\site-packages
  2. Opret en fil python37.pth
  3. Rediger filen for at inkludere dette C:\\Users\\\\my_linjemodul

Den lange version; Læs


I de fleste tilfælde vil redigering af PYTHONPATHfra GUI'en Indstillinger gøre tricket. Tricket forklares godt i dette Stack Overflow-svar.

Hvis du i første omgang kun ønsker at redigere din sti lokalt , vil dette nyttige svar gøre.

Lidt udvidet Varenr. 1

Hvis du ikke har C:\Users\\Anaconda3\Lib\site-packages, skal du igenplace C:\Users\ username> with the path to your Anaconda3.

Slightly Extended Item no. 2

If you are using Python3.7, create a file called python37.pth. Else create a file called python t;.pth for whatever Python version you are using.

  • Not sure which version?

    Under C:\Users\\Anaconda3\ search for a file of the form python<XX>.dll. The 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\\Anaconda3\Lib\site-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. 3

Assuming the SuperCoolClass you wish to import is located at

C:\Users\\my_project_folder\my_awesome_file.py .

Then open your newly created python t;.pth file with your favorite text editor (please don’t say it’s Vim) and add one line:


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 .


Nothing 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.