Changing directory where pip installs packages - python

I have a python2.6 installed on Oracle linux.
I decided to use a newer python version and installed python 2.7.13.
I have also installed pip to manage packages.
Now if I use pip to install a package it still installs it to the old location: /usr/lib/python2.6/site-packages
Is there a way to force pip to install packages for the newer python 2.7 version?

Posable Repeat Post
"Use a version of pip installed against the Python instance you want to install new packages to.
In many distributions, there may be separate python2.6-pip and python2.7-pip packages, invoked with binary names such as pip-2.6 and pip-2.7. If pip is not packaged in your distribution for the desired target, you might look for a setuptools or easyinstall package, or use virtualenv (which will always include pip in a generated environment).
pip's website includes installation instructions, if you can't find anything within your distribution." ~Charles Duffy
Taken from How to install a module use pip for specific version of?

Did you check Install a Python package into a different directory using pip?.
To install in specified target directory use "pip install --target= "

Oracle Linux uses the system-installed version of Python for almost all of its command-line utilities, so changing that could irreparably damage your system.
Instead of replacing the default Python install, you should strongly consider using Python 2.7 from Software Collections instead.
Using Software Collections means that the install of Python 2.7 is separated from the system install, so you don't run the risk of damaging your system. You can then make it available to your applications via the scl tool.

Related

When using pyenv to manage python versions, how do I install dependancies?

I'm on Ubuntu 22.04. On a default install there is no python version.
I've installed pyenv in order to use specific python-based programs.
Some of the programs I want to install have dependencies that are usually installed using pip. However, because there is no system python on-board, there is no pip.
Now, I could go and install system python, in which case I'd have access to pip... and also install python3 in order to use install python3 deps. But this seems like overkill to me. And for all I know, I might be creating complications that hit me further down the road.
So how do I do dependency management when using managed python versions?

Pip install location

I have python2.7 and python3.6 installed side by side in my computer. Now when I install a package using "pip install", how can I know in which python's site-packages is my package going to be installed?
Thank you.
When you have both version 2 and 3 installations pip and pip3 differentiate the target installtion.
For installing anything on Python 3(versions 3.5 and above) use pip3
for Python 2.7 use pip
Make sure python path is set in environment variables too.
also you can use where pip or which pip as #mshsayem mentioned.
Additional Reference
if you use virtualenv, the modules are located in:
{path_to_your_virtualenv}/lib/python{your_python_version}/site-packages/
and if you don't use virtualenv, normally are installed in:
/usr/local/lib/python{your_python_version}
You have to use pip3 for install python3 modules.
Check where a specific package is installed by:
pip3 show <package_name>
List all installed packages with install locations by:
pip3 list -v
Check the install location used by default when installed without sudo:
pip3 --version
and the location for packages installed with sudo, meaning system-wide installation:
sudo pip3 --version
You can find the location of pip by which pip. Then you view the pip executable header using head `which pip` or using your preferred editor. You can find the python interpreter location on the first line. You may have a pip2 and a pip3 executable.
By the way, you can run pip as a python module by python -m pip <command>. In this way, you can specify your python interpreter.
The answer to you question is divided to two parts:
1. Which python version the native terminal selects for me?
2. How do I specify which python version to use?
Which python version the native terminal selects for me?
In windows, the default pip that will be used is the one associated with the default python version you use. You can edit it in the PATH environmental variable (Start->find-type "Environmental" and click "Edit system variables"). Look the PATH variable and see which version of python is listed. If both versions are listed, windows will select the first.
See more information on system environmental variables here.
In Ubuntu/Linux, usually pip is associated with the native legacy version (2.7), pip3 is associated with Python3.5.x and pip3.6 is associated with Python3.6.x.
However, if you are using Unix OS (such as Ubuntu) or Mac, it is highly recommended to use virtualenv and activate it. See Official documentation to see how to use it. It's true for both Python2.7 and
Python3.6. In short, you will create a lightweight copy of you python installation without any packages, and, your installed packages will be installed within this virtual environment. Once you activate a virtual environment, the pip is associated with this environment.
How do I specify which python version to use?
You have multiple choices to specify in which environment you want to install the package. It depends if you are on Windows/Linux/MAC.
Shortly, you have the following options:
Use an IDE and let it help you manage your packages (e.g. Pycharm). Using PyCharm, you will find it very easy to use its package manager. You can also open the IDE's terminal and when you use pip, it will use the package manager of the selected interpreter. See official documentation.
Use OS native terminal and specify the version. In windows, the easiest way is to go to a command line or powershell, and type "c:\path\to\python.exe -m pip install ". On Ubuntu, use pip/pip3/pip3.6. Again, on Ubuntu it is highly recommended to use venv (virtual environment) since installing wrong package on the wrong version can interrupt the native python (Ubuntu uses python for multiple reasons such as the GNOME GUI).
Use virtual environments. You can look it up, there are plenty of threads explaining on that, as well as the Official documentation.

pip install packages for python 3

I don't know what I have did but now when use pip to install a package it install it for python 3 (python3.3 folder) not for python2.7.
Another problem I installed django_debug_toolbar and now my django version is 1.6.4 not 1.3 I installed.
Now I can't remove django 1.6.4 with pip. Do you have a solution?
Learn using virtualenv. It allows you to have different environments with isolated version of Python and set of installed packages. Each created virtual environment is by default having pip installed.
You messed up things (as you know very well) as you probably reinstalled pip for another version of Python.
You might find more versions of pip in your system. Check the version of python they use (on Linux watch the shebang on first line). Use explicit path to proper pip to manage packages for related Python.
Often people install pip and rename it or give an alias - names like pip33 or pip27.
Note, that virtualenv allows creation of different environments (with different Python versions) without need to install virutalenv for each of these Pythons.
With virtualenv I would also highly recommend using virtualenvwrapper which adds a few very handy commands.
My problem came when I installed django_debug_toolbar. when I pip-installed django-debug-toolbar, the latest version of Django was installed automatically.

Python site packages: How can I maintain for both 2.x and 3.x version

I understand that we can install different version of Python on a same box - but there are packages that are not supported common to both.
So if I have two version of Python(2.x and 3.x) installed how can I automatically have packages deployed correctly for each version of Python using pip?
At least on Arch Linux, and presumably on other distros, there are two separate packages for pip, which if both installed give you two different commands: pip and pip3. Running pip ... will always install to the Python 2 site-packages, and pip3 ... to the Python 3 site-packages. This works both for system-wide packages (running as root) or for installing them into your home directory.
I don't know if you can configure pip to install packages for multiple Python versions automatically, but it's easy to manually specify two packages on the command line, and it would be trivial to write a script that would call pip multiple times with the correct Python versions.

Enthought python not recognising system modules

I have installed the Enthought Python Distribution (i.e. python 2.7) on a Ubuntu 12.04 virtual machine and it would be very useful if it could recognise modules imported via the synaptic package manager. Currently, these are only recognised by the system-provided python installation (quite understandably). Since both pythons are 2.7, is it possible to make my EPD installation recognise the system modules? Thanks.
No, using synaptic-installed modules with EPD is not supported. Of course, you can try adding specific packages to your PYTHONPATH, but this is likely to create conflicts, especially for modules containing C-extensions that may be linked against a slightly different version of Python.
Currently, the recommended way to install python packages in EPD is with the enpkg tool. Try enpkg -s <packagename> to see if your desired package is in Enthought's repository. If you haven't already, you should upgrade enpkg itself by running enpkg enstaller and enter your EPD credentials by running enpkg --userpass. Then you should be able to install supported packages with enpkg <packagename> (Using enpkg to update EPD packages).
If the package you're looking for isn't in Enthought's repository, you can install pip with enpkg pip and install packages in EPD with that tool.
Alternately, you can download the source for your desired package and install it with python setup.py install, assuming the package has a setup.py.
Note: if you install a package into EPD without using enpkg, you should make sure to remove the EPD version of the package first if it exists (enpkg --remove <packagename>). If you later choose to install the package with enpkg, you should first remove the version you installed with an alternate method (Using non-EPD package installers such as pip).
There is also an upcoming GUI package manager from Enthought, currently in Beta.
Had the same problem.Enthought distribution uses completely different python paths and library prefix than your run of the mill system distribution. So if you use pip, pip will install on your system path, not your EPD path.
Solution:
1) get your EPD prefix with: enpkg --path
2) write it down somewhere
3) if you pip install then type:
pip install --install-option="--prefix=$PREFIX_PATH" package_name
as written by Ian Bicking on Install a Python package into a different directory using pip?.
The previous answer might be obsolete. On version 4.6.3 use enpkg --env to get the prefix
$ enpkg --version
enstaller version: 4.6.3
$ enpkg --env

Categories