Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I reinstall each module again if I install a new vesion of Python?

I just installed Python 3.6 and run terminal, tried to import any of the modules I already installed in 3.5 (rsa, matplotlib, enchant, ...) and it returned:

ModuleNotFoundError: No module named 'module_name'  

However, they still work when I run Python 3.5. What should I do?

like image 926
Mehdi K. Avatar asked Oct 17 '22 13:10

Mehdi K.


1 Answers

If you install a different Python version you will not have the modules you did already install for your old version.

Each Python version you install has its own working directory, and its own modules. Modules installed for a certain version of Python, in general, cannot be used by other versions, older or newer. This is because Python modules often need precompiled files and version-specific features to work on a certain version of Python. For example, you cannot use a module for Python 2.7 on Python 3.6, since that a lot of stuff changed from version 2 to 3.

This means that you will have to re-install any module you need on the new version of Python again, which can easily be done using PIP running pythonX.Y, where X.Y is the version number, like this:

python2   -m pip install SomePackage  # default Python 2
python2.7 -m pip install SomePackage  # specifically Python 2.7
python3   -m pip install SomePackage  # default Python 3
python3.6 -m pip install SomePackage  # specifically Python 3.6

Note also that copying the old site-package folder is not the same thing as reinstalling the modules, and should never be done.

like image 112
Marco Bonelli Avatar answered Oct 21 '22 02:10

Marco Bonelli