Say I have a python application that I want to install and if I run python setup.py install --user, everything gets put into ~/.local as expected (on linux), and inside of that the stuff in ~/.local/lib/python2.7/site-packages/
gets seen by the PYTHONPATH as expected; however, my executables that are created by setup.py (using either entry_points via setuptools or scripts via distutils) are correctly put into ~/.local/bin, but are not seen by the PATH at the command line.
Thus, I have to add $HOME/.local/bin to my PATH (via my .zshrc) to get these executables seen by my environment. I'm assuming this is the expected behaviour, but my question is, is there some way to get my executables "registered" with my PATH when I run the installation with the --user flag during the setup?
I believe this should work, as I see that ipython does something like this, where if it's installed with the --user flag (into ~/.local), then you don't have to add to your path ~/.local/bin to get the local install of ipython seen at the command line. I just can't figure out how ipython does it. Many thanks in advance.
Instead of using --user, why not use a virtualenv? they are much more flexible, and put its bin directory on the path when activated.
Otherwise, manually putting ~/.local/bin on your PATH, as you did, is what you need to do.
Related
I've installed pip on my computer(mac), and I tried these:
$export PYTHONPATH=/usr/local/lib/python2.7/site-packages/pip
$python pip freeze list
/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'pip': [Errno 2] No such file or directory
It doesn't work, but if I specify this full path into python command, it works:
$python /usr/local/lib/python2.7/site-packages/pip freeze list
ant==0.1.0
appnope==0.1.0
astroid==1.4.8
backports-abc==0.5
........
Why is that?
Running pip freeze directly should be sufficient. You shouldn't have to run it via python pip or tweak $PYTHONPATH at all.
The error in that first snippet has to do with how you are invoking python. Your command is interpreted as python <script-filename> [script-arguments ...]. The filename you are passing in is pip, so python looks for a file named "pip" in the current directory. That file does not exist, so python crashes with a "file not found" error.
python <full-path-to-script> works because... well, why wouldn't it? Python finds the script and executes it.
As pointed out in the comments you don't want to mess around with PYTHONPATH. If you want to have different versions of python on the same computer or python installations with different installed packages (or modules) what you need is to use virtualenv
Create a new virtualenv.
virtualenv /usr/local/custom-python/
and then whenever you want to use it or install packages into it, just do
source /usr/local/custom-python/bin/activate
try to use:
$export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages
Firstly, your code may cover the orignal PYTHONPATH which is deprecated. Secondly, do not include pip into the python path because pip is a package that should be included.
python /your/path/to/pip this pip is a folder in which there is a __init__.py . So python can read it. But if you directly define PYTHONPATH to pip folder, python will not find this __init__.py to represent pip (See document about python import packge)
Besides, I think you can include the binary pip (may located /usr/bin) in into your path so that you can call it directly with $ pip command
After using macports pip-2.7 to install pyflakes, I can run it manually from the pip installation directory using the command line like:
python /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyflakes myfile.py
However, I'm trying to get my mac emacs environment setup with elpy, and flymake seems to not be able to find pyflakes, giving me a dialog when I open up a python file in elpy mode saying:
Flymake: Failed to launch syntax check process 'pyflakes' (with args myfile.py): Searching for program: no such file or directory, pyflakes. Flymake will be switched off.
I could go into /opt/local/bin and try to write my own executable file that runs the above python command. But that seems hacky and there must be a proper way to install/setup pyflakes such that flymake can find the command without manually creating wrapper scripts, isn't there?
I can run it manually from the pip installation directory using the command line like:
python /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyflakes myfile.py
Unless this directory is in your $PATH, Emacs has no way to know where to find pyflakes.
One option would be to create a symbolic link, e.g.
ln -s /opt/local/.../python2.7/site-packages/pyflakes /opt/local/bin/pyflakes
Of course, you will have to use the full path. I shortened it for readability. This is relatively common on Linux machines, though I don't know how broadly it is used on OSX.
Another option, one which I prefer, would be to reinstall pyflakes using pip install's --user option:
--user
Install to the Python user install directory for your platform. Typically ~/.local/, or %APPDATA%Python on Windows. (See the Python documentation for site.USER_BASE for full details.)
--user is great for installing things that you might want to run independently of any particular project, like pyflakes. It installs things to your home directory instead of to a system directory, so you don't need any elevated privileges to use it.
You may have to add the user location to your $PATH variable, but you'll only have to do this once. Any future tools installed using pip install --user will become available immediately.
On my Linux machine, the directory that I had to add to my $PATH is ~/.local/bin/.
I encounter a problem when installing pip for python2.7. I downloaded the file get-pip.py, and install it successfully:
bogon:haha itensb$ python get-pip.py
Requirement already up-to-date: pip in /Library/Python/2.7/site-packages
Cleaning up...
But when I run the command pip, I got:
-bash: pip: command not found
I think it is the PATH not set appropriatelly , But I new on Mac. I need your help , thanks!
Use python -m pip. If you want the pip command check out #user3282276's answer.
Sounds like your PATH variable is not set to include the location that pip was installed to. On Macs and other *nix like operating systems when you type a command in the command line, what is actually happening is the shell is trying to find the executable file in a predefined area, called the PATH variable. If you are interested check out this question, https://superuser.com/questions/284342/what-are-path-and-other-environment-variables-and-how-can-i-set-or-use-them.
You are able to see what yours is set to if you do this in your command line
echo $PATH
this will give you some file paths separated by colons, for example when I type the command above I get this:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/Applications/Android Dev Tool/sdk/tools
which means that my shell will check for a executable in each of these files, if it finds it, it will run otherwise it will tell you the program can't be found. As a side note this is the reason why when you run an executable not in one of these PATH files you must do,
./program
this is specifying a relative path to the executable file, the current directory that you are in.
So for you, you installed pip to this directory:
/Library/Python/2.7/site-packages
chances are the above echo statement did not include this file, if it did then you have another problem. What you need to do is to update your PATH variable to include this directory as well. To do this you add an export statement to your .bash_profile (or .bashrc on Linux) in your home directory (this is a hidden file) that includes your current path variables (so you will still be able to run everything installed in the proper place) and this new directory that you installed pip to. To do this add this line to the end of your .bash_profile
export PATH=${PATH}:/Library/Python/2.7/site-packages
and you should be good to go. However before it will take effect you need to close and open your terminal window again or run source .bash_profile. You can verify this worked by running the echo command above, it should return the same thing but this time with /Library/Python/2.7/site-packages appended to the end.
Note: By the way the which command that you were told to run in the comments locates a program within the users path, which is why it did not return anything to you. Also since you will probably run into this soon enough there is also a variable called PYTHONPATH (look here) which tells python where to look to import modules. You should set this to whatever directory you have pip installing modules to if it is not already set.
Install python3 first, then use pip3 to install packages.
brew install python
python3 will be installed, and pip is shipped with it. To use pip to install some package, run the following
pip3 install package
Notice it's pip3 because you want to use python3.
My same answer here
to run the command, it works
sudo easy_install pip
I have set up a SSH connection to a remote server. I want to run some of my python programs on it so am having to download all the modules I had been using.
I just downloaded Ananconda (I don't have root access so installed it in ~) and added ~/anaconda/bin to my PATH. However when I try import numpy in Python, it says the module is not found. How do I fix this?
You might be running the wrong version of Python.
To check, use which -a python
james#bodacious:~$which -a python
/usr/bin/python
james#bodacious:~$
In my case, I'm running the version from /usr/bin/python, and that's the only version found in my $PATH. You should see the version from ~/anaconda/bin in your list as well, and for it to be run when you type python it needs to be at the top.
If it's not, you can check your $PATH and, if necessary, add ~/anaconda/bin to the front of it.
james#bodacious:~$echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/james/bin
james#bodacious:~$PATH=~/anaconda/bin:$PATH
james#bodacious:~$echo $PATH
/Users/james/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/james/bin
james#bodacious:~$
I haven't any Fedora/Redhat systems handy, but I believe you can:
yum install numpy
HTH
You've said that all you really want is to be able to use numpy - based on that, using anaconda is probably overkill.
It sounds as though what you're really asking is "Since I don't have root access and can't install system packages, how can I set up a python environment in my home dir that has what I need?"
This sounds like a job for... Super Grover! no wait, I meant virtualenv.
Hopefully your system will already have virtualenv installed for you. If it does, it's fairly simple for you to create your own environment with your own set of packages:
james#bodacious:~$mkdir venv/
james#bodacious:~$cd venv/
james#bodacious:venv$virtualenv .
New python executable in ./bin/python
Installing Setuptools..............................................................................................................................................................................................................................done.
Installing Pip.....................................................................................................................................................................................................................................................................................................................................done.
james#bodacious:venv$source bin/activate
(venv)james#bodacious:venv$pip install numpy
Downloading/unpacking numpy
Downloading numpy-1.7.1.zip (3.1MB): 3.1MB downloaded
Once that completes, you'll have your own copy of numpy which you can access in this environment just by using cd venv; source bin/activate to set your $PATH and $PYTHONPATH to point at your custom install.
If you don't already have virtualenv installed things get more tricky....
I am having real trouble installing SUDS in python 2.6.4. I have tried to install the setup file but it says the location of python cannot be found. This is because I have changed the location of python. I have tried to use easy_install but am having no luck. Does anyone know a simple way to do this or have a link to clear installation instructions.
Command that I entered was:
python setup.py install
The result I recieved was:
running install
error: cannot create or remove files in install directory
The following error occurred while trying to add or remove files in the
installation directory:
[Errno 13] Permission denied: '/usr/local/lib/python2.6/site-packages/test-easy-install-9203.write-test'
The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/usr/local/lib/python2.6/site-packages/
Perhaps your account does not have write access to this directory? If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account. If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.
For information on other options, you may wish to consult the
documentation at:
http://peak.telecommunity.com/EasyInstall.html
And if I have to change the python path how exactly do you do this.
I have tried what one site said to do and it was to first, create an altinstall.pth file in Python's site-packages directory, containing the following line:
import os, site; site.addsitedir(os.path.expanduser('~/lib/python2.3'))
Then it says modify distutils.cfg in the distutils directory with:
[install]
install_lib = ~/lib/python2.3
# This next line is optional but often quite useful; it directs EasyInstall
# and the distutils to install scripts in the user's "bin" directory. For
# Mac OS X framework Python builds, you should use /usr/local/bin instead,
# because neither ~/bin nor the default script installation location are on
# the system PATH.
#
install_scripts = ~/bin
Have you tried setting PYTHONPATH to the location of python? Maybe this way it will know, where to install it.
You are calling it with python setup.py install. Try sudo python setup.py install, if you are using some linux and you are sudoer.
I got messages like this too when I installed suds and python-ntlm. Our site has a separate areafor installations so that we can maintain multiple versions, so my first installation step was
python setup.py install --prefix=/install/suds/suds-0.4
and I got the same messages about installplace. To fix:
Make sure the directories are there with
mkdir -p /install/suds/suds-0.4/lib/python2.6/site-packages/
(This surprised me a little, I thought setup would build the directories.)
Make sure you have write permission down the tree with
chmod -R 775 /install/suds/suds-0.4/lib/python2.6/site-packages/
Neither of which got rid of the message!
The last step was to put the install area into PYTHONPATH, and then do the setup.py
export PYTHONPATH=/install/suds/suds-0.4/lib/python2.6/site-packages:$PYTHONPATH
python setup.py install --prefix=/opt/sw/fw/qce/suds/suds-0.4
with a final chmod to make the newly installed files readable in case umask is set to something restrictive:
chmod 755 /install/suds/suds-0.4/lib/python2.6/site-packages/*
After this I could start python and import suds. The key step was the putting the suds site-packages directory into PYTHONPATH.
I expect this help comes too late to help the original poster, but I hope it helps someone else who come to SO with this question. As I did.
I would need more details of your OS to give a fully accurate response. From the sounds of your question, you changed your path of python. Normally you'll have a preinstalled version of python that is compatible with your OS. For example, CentOS 5.x comes with python 2.4, however you can do a yum install of python 2.6. Once installed, you can run python 2.6 by the python26 command.
When doing installs and packages, I would recommend that you try to use package managers as much as possible, as they help take care of your dependencies, such as yum. Yum also helps control updating packages instead of having to do updates manually. The next best thing is to do installs via pip or easy install, in the case of this question, you can try easy_install https://fedorahosted.org/releases/s/u/suds/python-suds-0.4.tar.gz (requires setuptools), and as a last resort, you can try to do the manual install. I if I get the point that I'm doing a manual install, I feel I failed somewhere :)
Others have given good detail on on how to do the install manually.
Good luck.