Azért vagy itt, mert a következőket használod:
- Windows operációs rendszer 10+ verzió
- Python 3.3+ verzió
- Anaconda3
És PYTHONPATH
véglegesen szerkeszteni szeretné .
TL; DR
- Menj a
C:\Users\\Anaconda3\Lib\site-pa
ckages-be - Hozzon létre egy fájlt
python37.pth
- Szerkeszteni a fájlt, hogy ezt a vonalat
C:\\Users\\\\my_
modul
A Hosszú változat; Olvassa el
Prológus
A legtöbb esetben PYTHONPATH
a Beállítások GUI-ból való szerkesztés fogja cselezni. A trükk jól meg van magyarázva ebben a Stack Overflow válaszban.
Ha eleve csak az útvonalát szeretné helyben szerkeszteni , akkor ez a hasznos válasz megfelelő lesz.
Kissé kibővített Cikkszám 1
Ha nincsenek C:\Users\\Anaconda3\Lib\site-pa
ketreceid, írd újraplace C:\Users\
Slightly Extended Item no. 2
If you are using Python3.7, create a file called
python37.pth
. Else create a file called python
Not sure which version?
Under
C:\Users\\Anac
onda3\ search for a file of theform python&l
t;XX>.d
ll. The indicates the version number you need fo
r 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-pa
ckages 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
Slightly Extended Item no. 3
Assuming the
SuperCoolClass
you wish to import is located at
C:\Users\\my_project_folder\my_awesome_f
ile.py .
Then open your newly created
python
line:
C:\\Users\\\\my_pr
oject_folder.
Yes, with those annoying dou
bl
e slashes \\ .
No, wit
ho
ut quotes "" .
And that’s it.
Now you can import from anywhere, like a normal person:
from my_awesome_file import SuperCoolClass
.
Epilogue
Epilogue
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.

Original text