简体   繁体   English

永久修改 python 路径

[英]modifying python path permanently

I want to permanently add a directory to the path to load the functions and modules that I will create in the future.我想在路径中永久添加一个目录,以加载我将来创建的功能和模块。

For example: C:\Users\XXX\Lib1例如:C:\Users\XXX\Lib1

Inside it there would be a structure similar to the following one:在它里面会有一个类似于下面的结构:

Lib1/    
    /m1/__init__.py
        1.py
        2.py
    /m2/__init__.py
        a.py
        b.py

I want to use the libraries independently of where the current file path is located (ex: import lib1... m2.a(x,x,x) )我想独立于当前文件路径所在的位置使用库(例如: import lib1... m2.a(x,x,x) )

I'm using python 3 with anaconda3 on windows 10我在 windows 10 上使用 python 3 和 anaconda3

Using the following commands, I achieve my objective, but when I close python the changes are not saved.使用以下命令,我实现了我的目标,但是当我关闭 python 时,没有保存更改。 I have to run them every time I open python again.每次我再次打开 python 时,我都必须运行它们。

import sys
sys.path.append('C:\Users\XXX\Lib1')
       

thanks in advance for your help在此先感谢您的帮助

Set the PYTHONPATH environment variable.设置PYTHONPATH环境变量。 Use setx to modify the user environment from a command prompt.使用setx从命令提示符修改用户环境。 Add /M switch if you want to modify the system environment (all users).如果要修改系统环境(所有用户),请添加/M开关。 See setx /?setx /? for other options.其他选项。

setx PYTHONPATH c:\users\xxx\lib1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM