7

I've got python 3.7 installed on Windows 10. The recommended way to upgrade to 3.8 appears to be to do a new installation, which means I will have both versions installed. I don't need both versions, but I would like to keep all the packages I installed for version 3.7.

How do I achieve this please? Also will new new path variable for 3.8 replace the one for 3.7?

The process for such a common use case seems strangely complex. Am I missing something?

Robin Andrews
  • 3,514
  • 11
  • 43
  • 111
  • have you seen [this](https://stackoverflow.com/a/57292808/4636715) which states "If you are upgrading from 3.x to 3.y (minor) then you will be prompted with "Install Now". In this case, you are not upgrading, but you are installing a new version of Python. " – vahdet Mar 05 '20 at 14:20
  • _I don't need both versions, but I would like to keep all the packages I installed for version 3.7._ Why is that? Are you not using virtual environments? _The process for such a common use case seems strangely complex._ I'm actually curious to know how common it really is, unfortunately I don't know of any relevant statistics. _Am I missing something?_ :p – AMC Mar 05 '20 at 16:31

3 Answers3

3

One way to do this is to run:

python3.7 -m pip freeze > installed.txt

Then, after installing the new Python version you can install the packages with:

python3.8 -m pip install -r installed.txt

There is a chance that the packages you installed for your old Python installation are not compatible with the new version. For that reason it is safer to keep both Python installations and then use virtual environments for each of your projects.

You can create a virtualenv for each of your projects, using the Python version you need for that project, and install your dependencies only in the virtualenv for that specific project. This way you can avoid the situation where project A requires an old version of a certain package but project B requires a newer one. If you install all your packages globally you run into problems in this case.

See also What is a virtualenv, and why should I use one?

Lomtrur
  • 1,703
  • 2
  • 19
  • 35
2

Simple solution would be in CMD to do

pip freeze > packages.txt

This will write all your current packages to the text file 'packages.txt'

Then uninstall Python 3.7 as you would any Windows program then install Python 3.8 and in CMD do

pip install -r packages.txt

This will install all the packages that you had before.

Though I would recommend using conda as that handless Python versions and packages for you, along with environments.

KJTHoward
  • 806
  • 4
  • 16
0

I would recommend moving over to conda to manage your environments.

https://docs.conda.io/projects/conda/en/latest/user-guide/install/windows.html

The current thinking for most of the development projects that I've worked on involving python is that the version and libraries are specified on a per project basis. Conda allows you to freeze the environment so that it's more portable. You can generate an environment.yml file that allows someone to recreate your environment from scratch, and you can maintain only the packages needed for a given project.

As per your original question, you can set the PYTHONPATH to point to the old and new directories. I can't guarantee that the libraries will work though since there could be version compatibility issues.

Eric Yang
  • 2,678
  • 1
  • 12
  • 18