Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
277 views
in Technique[技术] by (71.8m points)

function - 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:UsersXXXLib1

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) )

I'm using python 3 with anaconda3 on windows 10

Using the following commands, I achieve my objective, but when I close python the changes are not saved. I have to run them every time I open python again.

import sys
sys.path.append('C:UsersXXXLib1')
       

thanks in advance for your help

question from:https://stackoverflow.com/questions/65909212/modifying-python-path-permanently

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Set the PYTHONPATH environment variable. Use setx to modify the user environment from a command prompt. Add /M switch if you want to modify the system environment (all users). See setx /? for other options.

setx PYTHONPATH c:usersxxxlib1

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...