How to make Python 3.7 recognize the libraries installed in Python 3.6?

Asked

Viewed 995 times

2

I have installed on my computer the Python 3.6 for some time now.

Today I installed the Python 3.7.2. But when turning the import numpy as np, gave the following error:

in the module named numpy

In the Python 3.6 this error does not occur.

How to do the Python 3.7.2 access the modules used by Python 3.6?

  • Tried to pip install numpy?

  • I think you have to install in python 3.7 via Pip

1 answer

4

You cannot use the same libraries - the ones that are compiled for Python 3.6 will only work in that version.

However, it is easy to install the same libraries again for Python 3.7 -

You didn’t say how you installed python3.7, or what system you’re using. but if you know its folder - just use Pip for him . Eventually you can read about virtualenv and always create new virtualenv’s -

At first you have to type:

python3.7 -m ensurepip
python3.7 -m pip install numpy

If you are on Linux, and have installed Python in a system prefix (and not in your user folder), you may need to put "sudo" before the above commands.

In time: for libraries that are composed only of files .py, with nothing compiled until it is possible to share the installation between different versions of Python (and is not the case with numpy) - but this requires careful folder management in which libraries used by the two versions are installed, as well as always making sure that libraries that have compiled modules are never in that shared folder: it’s just not worth it.

In general, the opposite is done: for each project using Python (and a backend developer in a company that uses micro-services may have tens of different projects), one creates a virtualenv, where all libraries are installed - in the correct versions required for each specific project. This ensures that there is no library version conflict between different projects.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.