Reputation: 221
I have been trying to fix the python path on my cpu, and I originally was just trying to change my .bash_profile
, but that wasn't working, so I used
import sys
sys.pat.append(path/To/Module)
and now when I run my script, I get this error message
How can I either fix this issue or undo the sys.path.append(path/To/Module)
?
Also, is it possible to export multiple directories in the python path, and if so how do I do that?
Upvotes: 6
Views: 10798
Reputation: 1
recently I found that pycharm ide will automatically append certain directory to your sys.path if you marked that directory as Sources Root. So even if you use sys.path.pop(sys.path.index(**directory path**)
, it wouldn't work. Just unmark the folder and the issue will be solved.
Upvotes: 0
Reputation: 13
How can I either fix this issue or undo the >sys.path.append(path/To/Module)?
To undo the sys.path.append
, you just need to remove that line from your script. Since the path is only modified for your current script and not system wide until you edit the PYTHONPATH
.
Also, is it possible to export multiple directories in the python path, and if so how do I do that?
If you want to do it using sys
, you can do it like:
sys.path.extend(['/path1', '/path2'])
Upvotes: 0
Reputation: 22453
Have you tried sys.path.pop()
That will remove the last item that you added or indeed the last item on the PYTHONPATH, whatever that might be.
Upvotes: 1
Reputation: 2731
Note that if you add a path with sys.path.append() you do this only for the current session. No need to undo it.
Just remove the line from you python file.
Upvotes: 1