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?

SUPhys
  • 221
  • 1
  • 5
  • 8
  • 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... – mgilson Jun 23 '16 at 17:20
  • 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. – o11c Jun 24 '16 at 03:20

4 Answers4

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.

Ivonet
  • 2,492
  • 2
  • 15
  • 28
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.

Rolf of Saxony
  • 21,661
  • 5
  • 39
  • 60
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'])

curioswati
  • 13
  • 6
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.