How to move all modules to new version of Python (from 3.6 to 3.7)

Question:

I just upgraded to python 3.7 and I realized that all my modules stuck with the previous version. Even Django is not recognised anymore. How can I do to transfer everything to the new version? I am a little lost right now, don’t even know where the new version has been installed.

Edit:

When I do $ which python3.6 the terminal tells me it doesn’t exist, but I have a python3.6 directory in /usr/local/lib/, where all modules are installed.

In the same directory /usr/local/lib/ I also have a python3.7 directory with some modules installed but many are missing. However when I search for the file python3.7 in my finder it doesn’t appear. when I do $ which python3.7 the path is /usr/local/bin so not the same path as the directory.

Anyone sees what happened and knows how I can transfer all modules to python3.7?

Asked By: NicoBar

||

Answers:

In some cases, we don’t have the opportunity to pip freeze in old version–because I’ve already updated and old version have been purged! There are some measures I’ve taken to recover some of the packages but I’m NOT sure every package would work with this fix.(e.g. the packages built with wheels)

  1. mv /your/path/to/python3.{6,7}/site-packages/
  2. If the case is packages installed outside venv (in /usr/local/ or ~/.local), reinstall pip with get-pip.py, just to be safe.
  3. If you are recovering a virtualenv. Activate your virtualenv and use my script

Most of your packages should work by now. If anything malfunctions, pip reinstall would works. If you still want it 100% works, pip freeze now.

Answered By: ttimasdf

Even if the old python version has been removed, it is possible to use the pip of the current python version with the --path option to list all the modules installed in the previous version.

For example, migrating all my user installed python modules from 3.7 to 3.8

pip freeze --path ~/.local/lib/python3.7/site-packages > requirements.txt
pip install --user -r requirements.txt

Incidentally, I always use pip install with --user and leave the system wide installations to the package manager of my linux distro.

It is safer to re-install all packages due to possible compatibility issues:

pip3.6 list | awk '{print $1}' | xargs -I{} pip3.7 install {}
Answered By: Tianyi Shi

I’m not sure about all modules…but if you want to install a module specifically in python3.7, try this:

python3.7 -m pip install *module_name*
Answered By: Smriti Singh

I have an alternative
(Not sure if works outside Windows 10)

I’m currently migrating from 3.7 to 3.8 and the way I found to re-install my previous libraries was by using a script I had that updates all packages via pip install. (Assuming you installed your new Python version as your main version) This checks for all the packages I had and updates/install them in the new Python version.

Note: I prefer to run the script from the command line

  1. Use the file explorer to go to the folder where you have the script;
  2. Click on the path box, write "cmd" and press enter to open a command line from the folder where you are;
  3. Write "python name_of_your_script.py" and press enter to run the command.

The script (adapted from this solution):

import pkg_resources
from subprocess import call

packages = [dist.project_name for dist in pkg_resources.working_set]
[call("pip install " + name + " --upgrade") for name in packages]

I faced a similar problem, now that I upgraded from python 3.7 to python 3.8 (new)

I installed Python 3.8, but the system kept the python37 subfolder with the already installed packages(…Python37-32Libsite-packages) even with the Pyhton38 subfolder created, with the new python.exe.

Usually, it’s possible to keep on using the old libraries on your new Python version, because the existent libraries installation folder are already registered in your local computer system path (*).

Even though, I’ve had problems to use some libraries (some worked in Jupyter Notebook but not in Spyder). I tried the alternatives others proposed to migrate libraries but it did not worked (maybe I did not

So I used brutal force solution.. Not elegant at all, but it worked:

  1. remove the OLD python version folders from the system path or even remove the folder itself for good..
    Folders: C:UsersUSERNAMEAppDataRoamingPythonPython37
    C:UsersUSERNAMEAppDataLocalProgramsPythonPython37

  2. Reinstall the packages you need, preferably via Anaconda prompt.
    python -mpip install library_name
    OR
    pip install –user –force-reinstall package_name
    OR
    pip install –user –force-reinstall package_name == specify_package_version

The libraries will be installed at c:usersUSERNAMEanaconda3libsite-packages and recognized by your new python version.

(*) to add the folder to the PATH: System properties –> environment variables –> click "Path"–> edit –> add folder name)

Answered By: Dalciana B Waller

in older version of Python –run the command

pip freeze > requirements.txt

download and install newer version on python.. change the PATH variable to the new version
and run the command

pip install -r requirements.txt 
Answered By: KavithaV