Install psycopg2 for Ubuntu 18.04 with Python2 and Python3 [duplicate] - python

I'm now currently using Python on Ubuntu 15.10.
But in my OS, I have many different python versions installed:
Python (2.7.9)
Python3 (3.4.3)
Python3.5
PyPy
So, it got messy with the versions of the packages in different environments. For example, if I run:
pip3 install django
But in fact, I cannot import django inside python3.5.
Is there any efficient way to call the correct version of pip?
Note:
Don't suggest that I use virtualenv, I know about it and am seeking another solution.

Finally I found the solution myself, see the Docs:
https://docs.python.org/3/installing/index.html?highlight=pip#work-with-multiple-versions-of-python-installed-in-parallel
Just call:
pythonXX -m pip install SomePackage
That would work separately for each version of installed python.
Also, according to the docs, if we want to do the same thing in windows, the command is a bit different:
py -2 -m pip install SomePackage # default Python 2
py -2.7 -m pip install SomePackage # specifically Python 2.7
py -3 -m pip install SomePackage # default Python 3
py -3.4 -m pip install SomePackage # specifically Python 3.4

How about using pyenv?
You can switch the version.
$ pyenv install 2.7.X
$ pyenv install 3.5.X
$ pyenv local 2.7.X
$ pyenv global 3.5.X

This solution worked for me:
sudo python2.7 -m pip install [package name]

Why not using anaconda?
If you use conda, you can easily create/manage virtual env. For example, if you have root env python 3.4 and py27 env for python 2.7, you can easily switch between them use command source activate [env]
source activate py27
conda install SomePackage

Related

is it possible to install a software for all python3 versions existing in the system

I have python 3.5 and python3.6 both installed on ubuntu 16.04. I switch between them using the command sudo update-alternatives --config python3 and now I have python 3.6 as the default python3.
I want to build opencv from source, and I want it to be installed on all python3 versions (and on python2 as well). I know that it will be installed for python 2.7 and python 3.6, but how to install it for python3.5 too, at the same time?
Learn virtualenv and pipenv.
Environvment creation is basic skill for modern python.
I suggest pipenv:
pip install pipenv
mkdir py35 && cd py35
pipenv install --python 3.5
Enjoy!

Installing virtualenv

I installed Python 3.7.1 using home-brew, and on the command line typing python returns the default python 2.7.10 and python3 gives the home-brew installed version. Then using
python3 -m pip install --user numpy scipy matplotlib
I installed the required packages.
Now what I understand is that to use the home-brew version python I have to always use python3and the required packages are installed inside python 3's lib folder.
I want to install virtual env correctly. I want to know what command should I use if I want it to be usable with python3?
You don't need to install virtual env because venv module is included in Python 3 standard library.
To create a virtualenv under .venv subdirectory of the current working directory:
python3 -m venv .venv
From my understanding you want to create python3 environments. First install virtualenv using pip.
pip install virtualenv
Then you can create a python3 environment like this:
virtualenv -p python3 env_name

Installing to specific sub-version of python

I'm trying to use pip to install a program specifically to python 3.6.4, but when I run
py -3.6 -m pip install package
It installs to 3.6.1
However, if I try to specify the specific version of 3.6 I want with
py -3.6.4 -m pip install package
It returns this output
Unknown option: -3
I'm guessing the argument for the version does not allow for the second period or something, but does someone else know a way to get around this? I'd prefer to do this without uninstalling 3.6.1
You can use pyenv
You should isntall pyenv and run these command
pyenv install 3.6.4
pyenv global 3.6.4
python -m pip install package

How to pip install packages into different versions of Python

I have 2 Python versions
Python 3.4.3
Python 2.7.10
Env variable works with Python 3.4(in my system), so when I pip install*package_name it will only install the package into Python 3.4
I have a system variable for Python 2.7 -- %python27% -- also.
My question is; how can I pip install a package/module into Python 2.7 without changing the Env. Variable.
Note: %python27% pip install *package_name doesn't work.
Thank you.
You should have multiple executables of pip.
Use pip2 and pip3 interchangeably.
Anyway, you should consider using virtualenv package, initialize it like virtualenv -p /usr/bin/python2.7 env_name or virtualenv-3.4 -p /usr/bin/python3.4 env_name then each time you use your code, type source env_name/bin/activate and "python" should be aliased to virtualised version.
You can use pip for python2 and pip3 for python3.
Also you can try using virtualenv or pyenv
I had the same problem, but it was installing to Python 2.7 rather than Python 3.4. Using $ pip3 install *package_name solved the issue.

How to install django for python 3.3

I had python 2.6.1 because it was old I decide to install python 3.3.2 but, when I type "python" in my mac it prints it is version 2.6.1 and when I type python3 it shows that this is 3.3.2. I installed django 1.6 but when I check, understand that it is installed for old version of python (python 2.6.1). I want to instal it for my python 3.3.2 what should I do? any way to uninstall python 2.6.1 and when I enter python in terminal it's version be 3.3.2? I have mac os 10.6.8
You could use pip to manage the package for you. If pip is not installed.
use
sudo easy_install pip
to install it. Then
pip3 install django
would install django for your python3.
Use python3 to call python version 3 on the command line.
For projects you can use virtual environments:
$ python # this will be version 2
$ python3 -m venv myenv
$ source myenv/bin/activate
$ python # this will be version 3
where myenv will be the folder that hosts the libraries and binaries for that virtual environment. It will automcatically use the python version that was used to initialize this venv - in this case python3. This has the effect that once you activate the venv you can use python there and it will be version 3.
to setup django in pyton3
sudo apt-get install python3-pip
sudo pip3 install virtualenv
virtualenv -p /usr/bin/python3.X venv
source venv/bin/activate
congrats you have setup python3 django and now have many packages to work with
Note: X stands for the version of python
To install django for python3, you need to use pip3 instead of pip.
python defaults to python2.
pip defaults to pip for python2.
So, when you install pip using whatever package manager you have, you are essentially installing pip for python2.
To remove Python2: $sudo apt remove python
To install pip for python3:
$sudo apt install python3-pip
To install pip for python2:
$sudo apt install python-pip
Note: I am using apt package manager. You should use the package manager for your OS.

Categories

Resources