How to undo sys.path.append(pathToModule)
Asked Answered
N

4

6

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?

Nifty answered 23/6, 2016 at 17:14 Comment(2)
Remove that line? appending to sys.path should only change the lookup path for the run duration of that script. It won't affect other scripts...Berceuse
Generally, mucking with sys.path indicates a serious design flaw, the default paths should suffice. But your error looks related to LD_LIBRARY_PATH (or better, -rpath) actually.Kozhikode
E
1

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.

Enemy answered 23/6, 2016 at 17:23 Comment(0)
Y
1

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.

Yukoyukon answered 23/6, 2016 at 17:25 Comment(0)
L
0

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

Learnt answered 23/6, 2016 at 17:28 Comment(0)
B
0

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.

Babu answered 29/6, 2022 at 1:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.