remove item from python path - python

I have added a path to the system pythonpath on linux and now i've broken it. How may I remove it ?
[EDIT]
Finally i solved it removing the script that added that path + installing something to rebuild the path.

not directly programming related but....
'print' your pythonpath to a file, edit the file and export that as your new pythonpath
[edit]
I stand corrected, see Banang answer below
[/edit]

I don't think there is a concept of Windows-like environment variables in Linux; they are defined in various scripts (e.g. .bashrc). You can edit those in any text editor.
What exactly did you to do "break" your PYTHONPATH?

Related

How to set PYTHONPATH in Centos 7?

In Centos 7 system, what is the default pythonpath enviroment?
Before I make any pythonpath setting, the command "echo $PYTHONPATH" gives no output. After I make the following setting:
PYTHONPATH="{$PYTHONPATH}:/usr/lib/python2.7/site-packages:/usr/lib64/python2.7/site-packages/pandas:/app/anaconda2/pkgs"
export PYTHONPATH=$PYTHONPATH:/app/Jade
the command "echo $PYTHONPATH" gives the following output:
:/app/Jade
I don't understand why before "/app/Jade" there is an extra colon (:). And what is the correct way to set PYTHONPATH?
Best regards.
Yeping Sun
This has nothing to do with $PYTHONPATH but is a more generally PATH naming scheme. PATH is a colon-seperated list.
From What is path?
Thus, for example, to add a directory named /usr/test to a user's PATH variable, it should be appended with a text editor to the line that begins with PATH so that the line reads something like PATH=$PATH:$HOME/bin:/usr/test. It is important that each absolute path be directly (i.e., with no intervening spaces) preceded by a colon.
See more here: Python - PYTHONPATH in linux
export PYTHONPATH=/usr/lib/python2.7/site-packages:/usr/lib64/python2.7/site-packages/pandas:/app/anaconda2/pkgs:/app/Jade
The problem is in your first one, you included "" around $PYTHONPATH.
Secondly, the correct way to do this is:
export PATH=$PATH:/path/to/python
You can do which python to figure out what your path to Python is.
And then simply to export PYTHONPATH=/app/Jade <-- this may be incorrect as well since you need to supply this with an absolute path. Unless app is in your root folder, this won't work.
ALSO if you could copy-paste the exact error you are getting, that would be really helpful to the SO community in helping you, with this post and future posts.

How to undo sys.path.append(pathToModule)

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

Why would I add python to PATH

I am beginning to look at python, so when I found a tutorial it said that the first thing to do would be to download python from www.python.org/downloads/
Now when I downloaded python 3, I then started the installation and got to
Why would I want to "Add Python 3.5 to PATH"? What is PATH? Why is it not ticked by default?
PATH is an environment variable in Windows. It basically tells the commandline what folders to look in when attempting to find a file. If you didn't add Python to PATH then you would call it from the commandline like this:
C:/Python27/Python some_python_script.py
Whereas if you add it to PATH, you can do this:
python some_python_script.py
Which is shorter and neater. It works because the command line will look through all the PATH folders for python and find it in the folder that the Python installer has added there.
The reason it's unticked by default is partly because if you're installing multiple versions of Python, you probably want to be able to control which one your commandline will open by default, which is harder to do if both versions are being added to your PATH.
In addition to what #SuperBiasedMan stated, you can edit your PATH in Windows by hitting Start > Run, then type sysdm.cpl.
From there, navigate to Advanced tab and then hit Environment Variables.
In the lower section, where it says 'System variables', find the one named PATH and double click it. Note that it would be easier to copy and paste it to a notepad or something. The separator as you can see is a semi-colon.
Any path that you add to this variable, will be looked when you type any command in a cmd window or through the 'Run' command line.
That's the same concept as in Linux, I just pointed out how it can be edited.
This shows the way if you haven't add python to PATH(By the way, the python.exe is in my Python directory)
This is the way if you add python to a PATH

Python default site-package directory changed after installing Ruby

I have spent a few hours trying to solve this problem but didn't manage yet. I figure my question is a bit specific to my own mac configuration and I need a more detailed instruction.
So my problem is that I installed Ruby using home-brew, for some reason, this installation changed my default python site-package directory. Before I have Ruby, my terminal python will automatically call the site-package from the path '/Users/xxxxxx/canopy/lib/python2.7/site-packages'. However, it now will use '/Library/Python/2.7/site-packages'. I tried three different ways to solve this issue but all failed:
1 use Canopy Terminal like this Set Canopy Preference, but this method point to another directory '/Applications/Canopy.app/appdata/canopy-1.5.2.2785.macosx-x86_64/Canopy.app/Contents/lib/python2.7/site-packages', which is not i want either.
2 change the bash_profile like this amend path, but by just putting the # in every line of the bash_profile, it still use directory '/Library/Python/2.7/site-packages'. Btw, my bash_profile and $PATH looks like this before:
and looks like this
3 add the path '/Users/xxxxxx/canopy/lib/python2.7/site-packages' into sys.path, which look like this now:
But none of those worked. How can I make my terminal point to the path '/Users/xxxxxx/canopy/lib/python2.7/site-packages' now? Or ultimately, what should I do to clean up those different site-packages and use the one I only need?
Thank you for any help!
On a mac by default the path is /Library/Python/2.7/site-packages/foo.egg.
Before doing anything, in terminal, start a new Python session and do
import sys
print sys.path
If the paths are of the form /Library/Python/2.7/site-packages/foo.egg, then just follow link
tl;dr
Basically add this to your bash_profile,
source [...] /activate
VIRTUAL_ENV_DISABLE_PROMPT=1 source [...] activate
I found the solution:
added to the bash_profile this line " export PATH="$HOME/canopy/bin:$PATH" ", and uncomment all other lines in bash_profile.

How can I change default python version EMACS 23 uses?

Trying to change the version of python emacs uses. (OSX10.6)
In Terminal
python
brings up the version I've set up in PATH
But in EMACS it does not.
How can I change this?
Another option is to look into fixing the environment variable PATH for Emacs which is a little tricky when using Emacs on Mac OS. Just make sure that Emacs' PATH has the same value as PATH in Terminal.app/Bash. These links should help:
Accessing OS X / UNIX environment variables in Emacs minibuffer
http://www.emacswiki.org/emacs/EmacsApp
(cf. Section "Path" and "Alternative Path Solution")
The easiest way (assuming you are running the GUI version of Emacs), is to choose
Options->Customize Emacs->Specific Option
and type python-python-command, and fill in the path to the python you want. Then save for future sessions and you should be good.
I'm really not sure why it wouldn't be honoring the path variable. The default should be simply "python" (no path). Maybe you have already set this, or you are changing the command path in your .emacs? You could look in ~/.emacs and see if you are doing either of those.
try to add this to your .emacs or other config file:
(setq python-version-checked t)
(setq python-python-command "python2.7")

Categories