Migrating an env to a new python version - python

I have a python app build on python 3.4
Due to an OS update I have to update this app to python 3.5.
First step I did was this to create new python version path in env
python3 -m venv --upgrade ENV_DIR
But how can I reinstall the needed packages from requirements.txt into this new 3.5 path?
When I do
pip install -r requirements.txt
it says all packages are already installed.
What am I doing wrong? Can someone help me?
Thank you

You can also use pyenv for multiple python versions.
Install pyenv
check available python versions using pyenv.
pyenv install --list | grep " 3.[45]"
Install the version you want. Here you will need 3.4
pyenv install 3.4(Any version you want)
Find available versions
pyenv versions
Go to local folders where your project is there. Set python 3.4 version
pyeve local 3.4
Check python version. It would be 3.4
python --version
Create virtual Environment
python -m venv venv
Install all packages using
pip install -r requirements.txt

Related

install pip on python 3.7 ubuntu

I am working on ubuntu, I have python 3.8 as standard installation.
However as my project have dependency on python 3.7 I have installed 3.7 and removed 3.8
now when I am trying to install pip it is installing python3.8 again and getting installed with 3.8.
I am using apt-get -y install pip to install pip.
I want to install pip on top of my python3.7 installation so that pip uses python3.7
my project have dependency on python 3.7
This is where virtual environments really useful. The idea is that you create an environment in which the required version of python and packages can live without altering the installation of python you might want to keep installed for other projects.
There are a few options, but Anaconda / miniconda are a popular way of using virtual environments and fairly easy to use. First you'll need to install miniconda:
https://docs.conda.io/projects/conda/en/latest/user-guide/install/linux.html
After that from a terminal you need to create your new environment
conda create -n "py3p7" python=3.7
Then activate it:
conda activate py3p7
Then check that you've got pip installed and it's installed under the right python version:
pip --version
Which for me returns:
pip 22.2.2 from /home/MY_NAME/miniconda3/envs/py3p7/lib/python3.7/site-packages/pip (python 3.7)

Connection between pip and python [duplicate]

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

Downgrade Python version in virtual environment

I am always getting the same error regarding TensorFlow:
ModuleNotFoundError: No module named 'tensorflow.contrib'.
I am actually using Python version 3.9 but, reading online, it seems that version 3.7 is the last stable one that can work with TensorFlow version >2.0.
Unfortunately I have started my project in a venv with the wrong version of Python and I would like to downgrade it, how can I do that?
There's the venv --upgrade <ENV_DIR> command, but it's mainly intended to update between patch versions (e.g. from 3.9.15 to 3.9.16).
You'll need extra steps to update between different minor versions. Let me walk you through it.
Assuming you have both versions of Python installed:
$ python3.9 --version
Python 3.9.16
$ python3.7 --version
Python 3.7.16
And that your environment was created using version 3.9, and it's in a venv subdirectory:
$ . venv/bin/activate
$ python --version
Python 3.9.16
$ deactivate
Use these commands to downgrade from 3.9 to 3.7:
$ python3.7 -m venv --upgrade venv
$ cd venv/bin
$ ln -sf python3.7 python
$ ln -sf python3.7 python3
$ rm {python,pip}3.9
$ cd -
Here's the result:
$ . venv/bin/activate
$ python --version
Python 3.7.16
tf.contrib is deprecated from the latest version of TensorFlow 2.x and is replaced with TF Slim.
It is recommended to use the upgraded version of TensorFlow to have the benefit of the latest features and functionalities provided by TensorFlow.
However, To downgrade python
You need to uninstall the existing python version and re-install the required python version and set up your environment.
If you are using Anaconda IDE, then use the below command:
conda search python #to check available python version
conda install python=<version>
conda create --name <env_name> python=<python_version> # Which also creates virtual environment
activate <env_name>
Please check this link for more details.

Install Python 3.6.3 in Virtualenv using pip in WIndows 10?

How do you install Python 3.6.x in a virtualenv using pip in Windows 10?
pip install python, pip install python3, pip install python3.6 don't work.
Pip and virtualenv are two separate tools. Pip is a package manager, you will use it to install packages into your virtual environment once it has been set up. Pip does not actually manage the virtual environment. Virtualenv is the tool that handles creating virtual environments.
First, you should check if you have virtualenv installed with virtualenv --version. If you do not have it, you will get an error that virtualenv is not found. You can use pip to install virtualenv with pip install virtualenv.
Once you have virtualenv, you can create a python 3.6 environment with virtualenv -p python3.6 /path/to/myvirtualenv. You will need an installation of python 3.6 for this command to work, so download and install python 3.6 first if you do not have it.
I believe that on windows if you don't have python 3.6 in your PATH variable, you may need to point directly to the python 3.6 installation instead with virtualenv -p /path/to/mypython3.6 /path/to/myvirtualenv.
See Virtualenv User Guide

How do I change PIP to use Python 2.7

I am on AWS Ec2 Amazon AMI. Trying to install virtualenv but PIP is set to use Python2.6
# pip -V && virtualenv --version
pip 9.0.1 from /usr/local/lib/python2.6/site-packages/pip-9.0.1-py2.6.egg (python 2.6)
bash: /usr/bin/virtualenv: No such file or directory
# python -V
Python 2.7.12
I tried uninstalling virtualenv and reinstalling it but no luck.
#pip install virtualenv
DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6
Requirement already satisfied: virtualenv in /usr/local/lib/python2.6/site-packages
Here is the install directory:
# which pip
/usr/sbin/pip
# which python
/usr/bin/python
1.python2.7 -m pip install virtualenv
Reference Python official document
2.You can Install virtualenv for any python interpreter and use for a different python interpreter like:-
sudo pip3 install virtualenv
and then if you want to use python2.7 python interpreter then run following command to make virtualenv:-
virtualenv --python=/usr/bin/python2.7 virtualenv_name
NOTE :- python2.7 interpreter has to be present in /usr/bin/* folder
For more on above command see this answer

Categories