On Mac OS X, I've had the packages directory of /Library/Python/2.7/site-packages. However, after installing 64 bit Python from brew (Executing python in 64 bit mode on Mac OS X 10.10), I find that pip install installs the package into a new /usr/local/lib/python2.7/site-packages directory.
How can I control the target directory where the pip command installs the packages? I can I make the default target directory for pip from one to another?
You can, at least by calling the right pip. Thus, if you install pip through the base OS X Python (/usr/bin/easy_install pip, I would guess), then this pip (/usr/bin/pip, I would guess) will install new packages in the base OS X Python library (/Library/Python/…).
Now, you would normally not want to do this, and instead completely move to whatever Python you want to use (that would be brew's, in your case). In fact, this makes things simpler, since you have a single version of Python to care about, where you can put all the packages you need.
I simply revert back to original with reinstallation of pip with sudo easy_install pip. This installs /usr/local/bin/pip.
I also checked that the /usr/local/Cellar/python/2.7.9/bin/pip is symbolically linked to (overwritten) /usr/local/bin/pip.
I aliased a command alias pip64='/usr/local/Cellar/python/2.7.9/bin/pip' so that the brew's python package installation is executed with pip64 whereas the normal case is with pip.
Related
I have pip3, installed via the yum install of python3-pip.
I've done a pip3 global install of some modules I need, but python3 can't find them to import. After a little investigation I see that pip3 installed the modules to /usrlib/python3.6/site-packages/pip/_vendor/
The problem is that python3 doesn't seem to know to look at pip/_vendor, it only finds modules directly installed under site-package. If I just copy the modules from .../site-package/pip/_vendor to .../site-package everything works fine.
The issue doesn't appear to be related to file permissions or ability to read the modules.
I'm wondering how I configure either pip to install directly to site-package or python3 to understand how to look in the pip/_vendor location.
I'm configuring this all with ansible and would like as module an option as possible. For instance I could manually use an argument to tell pip3 to install to the folder I want, but I don't want to hardcode the exact site-package directory if I don't have to.
I recommend starting over with pip by downloading and running get-pip.py. This will not only install the latest version of pip, but it will also install packages to a Python-readable location (the version of Python you use to run get-pip.py).
As an aside, I would avoid installing packages system-wide unless there is a specific need for them. At the very least, you should be installing them as a regular user, and even better you should be using a virtualenv.
I need to work with Both Python 2.7.12 and python 3.5.2 simultaneously on my Ubuntu 16.04.1 LTS. Python 3 came pre-installed so I've no idea where it sits, in terms of path to the directory, while python 2 sits in /usr/local/lib/python2.7/.
I found lots of questions on SO and on askubuntu about how to install but nothing about how to use them separately, installing different libraries, and what should I avoid or be careful of, if I maintain this dual python thing for the long term? For example, I usually run pip install to install a library and I can check that its installed in my python2 directory but how do I install the same package for my python3 without conflicts? Something like: python3 pip install <package> ?? Where is the default python3 installed? And how do I call python3 for paths where python is not part of the command for example: pip freeze, sudo-apt get, etc.?
PS: I've not officially worked with Virtualenv but I've been informed that is usually good for isolating projects within a python language version, rather than isolating two different language versions from each other.
Please let me know.
Thanks
This is absolutely no problem, as Python does that for you. You don't need a virtualenv at all.
If you use Ubuntu packages, make sure you use the python3- versions for Python 3, and the normal python- versions for Python 2.
For example, python3-numpy and python-numpy.
If you use pip to install extra packages, you an either use the pip script with the version number appended: pip2.7 or pip3.5, or, my preferred method, call pip as a module for the respective Python executable:
python2.7 -m pip install <whatever>
and
python3.5 -m pip install <whatever>
Other than that, there should not be any issue: Python stores the packages in completely separate directories, and each Python executable only uses its respective directive.
Do not fiddle around with PYTHONPATH, unless you really know what you're doing. This has the danger of setting your PYTHONPATH to a directory with Python 2.7 modules and then using Python 3.5 to run things.
If you start from scratch, you may need to install pip first.
For the system Python(s), use the relevant package:
sudo apt install python-pip
sudo apt install python3-pip
For your locally installed Python(s), use the built-in bootstrapper module:
pythonx.y -m ensurepip
Note on the OS-installed Python executables:
Python 3.5 lives at /usr/bin/python3.5, Python 2.7 (the OS one) at /usr/bin/python2.7.
You could even use the OS 2.7 one next to your locally installed /usr/local/bin/python2.7 (and confuse yourself when a package can't be found because you used the wrong one).
Or install Python 3.6 next to Python 3.5 (provided you've used make altinstall, so python3 doesn't get overwritten).
This is also why you don't really want to run pip (or even pip2.7) as is: pip2.7 may get you the system one, instead of the one in /usr/local/bin/pip2.7, depending on your PATH.
(The same goes for the python2.7 executable, so if you need to specify the full path /usr/local/bin/python2.7 to run that one (or have an alias), the same holds for pip2.7. If, on the other hand, /usr/local/bin is first on your PATH, you should in principle never run into the same pip and python executables.)
I have an installation of Ubuntu 14.04, which comes with Python 2.7 by default. If I were to install a Python package "foo", I would normally run pip install foo. The pip executable is found in /usr/bin.
However, I have now installed Anaconda, and I want to use this as my default Python interpreter. This means that when I run pip install foo, I want it to call Anaconda's pip, rather than the pip that comes with Ubuntu. In this way, installing a new package will copy it to Anaconda's site-packages directory, rather than that of the native Python installation.
Now, in my .bashrc file, I added export PATH=/home/karnivaurus/Libraries/Anaconda/bin:$PATH, and in that path is Anaconda's pip. However, this means there now exist two pip executables on PATH. How can I ensure that one which is called is that within the Anaconda distribution?
How can I ensure that one which is called is that within the Anaconda distribution
Executables on the PATH are inspected from left-to-right.
PATH=/home/karnivaurus/Libraries/Anaconda/bin:$PATH
Will now always use the Anaconda binaries if present.
If you would like to use the native pip, then you will need to qualify its path like so
/usr/bin/pip --version
I was wondering how the above "yum install package" & "python setup.py install" are used differently in CentOS? I used yum install ... all the time. However, when I try to do python setup.py install, I always get: this setup.py file couldn't be found even though its path shows up under echo $PATH, unless I try to use it in its current directory or use the absolute path.
When you type python setup.py install, your shell will check your $PATH for the python command, and run that. Then, python will be examining its arguments, which are setup.py install. It knows that it can be given the name of a script, so it looks for the file called setup.py so it can be run. Python doesn't use your $PATH to find scripts, though, so it should be a real path to a file. If you just give it the name setup.py it will only look in your current directory.
The source directory for a python module should not, ideally, be in your $PATH.
yum install is a command that will go to a package repository, download all the files needed to install something, and then put them in the right place. yum (and equivalents on other distributions, like apt for Debian systems) will also fetch and install any other packages you need, including any that aren't python modules.
Python has a package manager, too. You may also find using pip install modulename or pip install --user modulename (if you don't have administrative rights) easier than downloading and installing the module by hand. You can often get more recent versions of modules this way, as the ones provided by an operating system (through yum) tend to be older, more stable versions. Sometimes the module is not available through yum at all. pip can't install any extra packages that aren't python modules, though.
If you don't have pip already (it comes with Python3, but might need installing separately for Python2, depending on how it was set up), then you can install it by following the instructions here: https://pip.pypa.io/en/stable/installing/
I am puzzled by the following behavior. I have Python 3.4 installed on Windows 7. Pip came installed with the Windows distribution.
When I try to install virtualenv (or any other package), or execute any other command, nothing happens:
C:\Python34\pip install virtualenv
(nothing happens)
C:\Python34\pip list
(nothing happens)
However, the python -m variants do work.
C:\Python34\python -m pip install virtual env
C:\Python34\python -m pip list
I know that the Python Packaging User Guide, in the section Installing Packages says to use python -m pip install [package name]. However, should 'pip install [package name]' also work?
I found in a previous post that they do the same things, so why is there a difference in behavior?
pip is installed into Scripts subdir.
Try C:\Python34\Scripts\pip -V to see what you are running.
C:\>C:\Python34\Scripts\pip -V
pip 7.1.2 from C:\Python34\lib\site-packages (python 3.4)
Otherwise your pip.exe process might be blocked by the running antivirus.
(Building on Radek's answer) There are two problems with using pip (and similar scripts in Scripts). The first is enabling the OS to find the file. You must either give the correct absolute path or .../Pythonxy/Scripts must be on the PATH. I believe making the latter true is optional when installing.
If you actually entered what you posted, I am surprised that Windows did not respond with the Win 7 version of "c:\programs\python35\pip is not recognized as an internal or external command, operable program or batch file." (from my Win 10 machine).
The second, when more than one version of Python is installed, is the ambiguity of which pip to run (with which python binary). Even if all Python installations have the same pip version, it must be run with the version whose site-packages directory is the intended target. Even when pip install xyz at the command line runs, it may or may not do what is intended.
The dependable solution to both issues is to specify a particular python binary (whether with .../python.exe, python, python2, python3, or py -x.y, and let that binary find 'its' pip and point it to the 'right' site-packages.