Python packages -- system and user's have different versions - python

if I have sudo pip install a python package to a system-wide location
and I pip install --user a different python package to my user location
What would python use when I do import packagename? How do I control the version? or python always uses the most updated one?

Related

Change path of pip and pip3

I want to create a user path to install packages installed by pip or pip3 for python 3.7.2, for that, I noticed that C:\Users\VVK\AppData\Roaming\Python\Python37\site-packages by py -m site --user-site and,
I wish to update it by C:\Users\VVK\AppData\Roaming\Python37\Scripts, How is this possible?
I am using Microsoft Windows 10 64-bit.
Python37\site-packages is used to install libraries while Python37\Scripts is used to install programs. The latter should not be used for package installation. Packages when installed should install their programs (executable scripts) into Python37\Scripts themselves.

python: installing matplotlib locally

I am a user without root privileges on a linux multi-user platform. I would like to install matplotlib (I have seen some questions on stackoverflow but they are old and related to previous versions of matplotlib). I think the thing I should do is installing from source python -mpip install .. I cannot find any way to install locally and not globally, as I don't have superuser privilege.
You can take a look here, on stackexchange the problem were solved.
As you can read:
Download the matplotlib and install it manually
install it using pip or easy_install
Manually:
cd /dir/of/your/downloaded/lib
python setup.py install --user
With pip or easy_install:
pip install --user matplotlib
easy_install --prefix=$HOME/.local/ matplotlib
If you have pyenv installed on the system you can easily switch to another python environment that has matplotlib installed.
For example, you can install the latest version of anaconda python, using tab key autocompletion to see which versions are available.
pyenv install anaconda3-5.2.0
Then you can switch your local python version using
pyenv local anaconda3-5.2.0
Now you can check your python version and matplotlib should be available.
On the other hand if pyenv is not currently installed, either ask your admin to install it or use a workaround script as described here.

Install package locally

I use python's pip to install packages. Now I want to install scipy, which is already installed on the system, but an old version and on a part of the system where I don't have access to. If I try
pip install scipy
pip rightfully tells me that the package is already installed. If I do
pip install scipy --upgrade
pip tries to upgrade the package but I don't have the access rights to do that.
How can I tell pip to install the package local to my user and to ignore the other scipy package?
I think the best way for avoid override packages it's using a virtual environment. Python has it's own virtual environment and you could install it by:
Python 2.7
> sudo apt-get install python-virtualenv
Python 3
> sudo apt-get install virtualenv
With modern python versions, virtualenv is usually included. Once installed, you could generate a virtual enviroment typing:
> virtualenv venv
This would create a folder in the current directory named venv (you could name it whatever you want). In this package the libraries will be installed.
So, it's time to activate the virtual environment
> source venv/bin/activate
You could verify the environment has been activated by checking the prompt changes. If it happens, all the packages installed using pip will be installed locally.
(venv)> pip install scipy
You could check this website for more info.
Don't forget that you eventually have to clear your $PYTHONPATH variable, in order for it to not pick up other packages.

Where should python pip install?

I am using a raspberry pi 2 board with Raspian. In order to be consistent with my mac I created a separate version of Python v2.7.10. I installed a number of packages that where recommended and I was able to compile it. I placed it in /usr/local/opt/Python2.7.10. I then updated my path environment so that this directory comes first. The original Python 2.7.3 is located at /usr/bin
Now I need to get pip installed. I downloaded get-pip.py and executed it. pip was installed in /usr/local/bin, which is not where either versions of Python exists. This doesn't look right to me. I am not sure if this pip is for the original Python or for the newer version of Python that I created. I just don't want to mix the two. Is this the correct location or do I need to get it somewhere in /usr/local/opt/? I am not sure how to get pip to install in /usr/local/opt/Python2.7.10/bin.
pip: dealing with multiple Python versions?
To use pip on a specific Python, you need to make sure you have downloaded pip and installed pip for that python version:
curl -O https://bootstrap.pypa.io/get-pip.py
/path/to/python27 get-pip.py
Then use specific pip version to install packages:
pip2.7 install somePackage

Python - No pip when creating a virtual environment

So I heard about the proper way to install packages into python by creating a new virtual environment for every project. Being on a mac (10.8) I have installed python3 using Homebrew, then I installed pip and virtualenv on this copy.
Now here comes the problem:
I create a new virtualenv, and activate it using:
virtualenv testing
source testing/bin/activate
When I type
which python
/Users/mik/Desktop/testing/bin/python
But typing
which pip
/usr/local/bin/pip
(learned of this when trying to install a package in the virtual environment, and it installed in the system wide installation in /usr/local/)
Inside the folder testing there is no file referring to pip
Extra Question: How does pip know which python to install the files to, for example pip list (which I believe refers to python 2.7) outputs the names of packages installed on python 3.3
I'll start with the last question as it explains what is happening.
The commands pip and easy_install are python scripts which are made executable on the filesystem. The python they use is the python that the first line tells to run the script. e.g. in /usr/bin/easy_install it is #!/usr/bin/python This will be Apple's python. So easy_install will install the 2.7 version of pip and virtualenv and will ignore your python3.3 setup.
The way to instal into python 3 is to install the 3.3 version of pip and virtualenv, the easiest way would be to install the Homebrew package for them. I think it is easier and less confusing to use just one package manager (Homebrew here) and not two (i.e. Homebrew and python).
You can also install easy_install directly. The way to do this is install the distribute package using python3.3 explicitly.
Python 3.4 will make this much easier as pip will always be available

Categories

Resources