question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot import numpy in Python 3.7 or Python 3.8 - Ubuntu 18.04

See original GitHub issue

Hello! Hope all the devs are staying safe during corona time and thanks for making such a great package.

I manage a group of users so I’m trying to figure out how I can install numpy for all of them to use without having everyone install the package themselves.

I have Python 2.7.17 and Python 3.6.9 (installed by default through Ubuntu 18.04). Additionally, I have installed Python 3.7.5, Python 3.8.0, and numpy using the following.

sudo apt install python3.7
sudo apt install python3.8
sudo apt install python3-numpy

If I run python or python3 or python3.6 which (invokes python 2.7.17 or python 3.6.9), I can run the following command just fine.

import numpy

However, if I try to run the above after running python3.7 or python3.8 I get the following error message:

ImportError: cannot import name 'multiarray' from 'numpy.core' (/usr/lib/python3/dist-packages/numpy/core/__init__.py)

When I install numpy it gets installed to /usr/lib/python3/dist-packages which should be fine since it’s on the sys.path() for all versions of Python.

Could it not be working because the version of numpy being pulled using apt is only for Python 3.6.9? If that’s the case, how should I install numpy for all users for ALL versions of Python?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

5reactions
rgommerscommented, Mar 24, 2020

When I install numpy it gets installed to /usr/lib/python3/dist-packages which should be fine since it’s on the sys.path() for all versions of Python.

That’s definitely not fine, NumPy contains C code and compiled Python extensions are specific to a minor Python version - you cannot mix 3.6 / 3.7 / 3.8

Could it not be working because the version of numpy being pulled using apt is only for Python 3.6.9?

Correct

If that’s the case, how should I install numpy for all users for ALL versions of Python?

You need to install a Python version per Python version. Probably as simple as:

sudo apt install python3.7
sudo python3.7 -m pip install numpy
sudo apt install python3.8
sudo python3.8 -m pip install numpy

and actually probably better to get rid of your apt-installed python3-numpy and do sudo python3.6 -m pip install numpy for symmetry

1reaction
matthew-brettcommented, Mar 25, 2020

For venv vs virtualenv - since a recent comprehensive refactor, virtualenv can now use venv under the. hood - see : https://virtualenv.pypa.io/en/stable/user_guide.html#creators

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot import numpy in Python 3.7 or Python 3.8 - Ubuntu 18.04
The problem is that the deb numpy-python3 only works with python3.6 . The (appallingly uninformative) error message is cause by a trial ...
Read more >
[Solved]-Cannot import numpy in python3-numpy
The following websites may help you: Numpy build fails with cannot import multiarray, Python ImportError "cannot import name 'multiarray'.
Read more >
Install Numpy on Ubuntu 18.04 Bionic Beaver Linux
Instructions. Python 2. Install Numpy Module from Ubuntu repository. The recommended approach is to install the stable Numpy module directly ...
Read more >
How to Install NumPy {Windows, Linux and MacOS}
Step 1: Check Python Version · Step 2: Install Pip · Step 3: Install NumPy · Step 4: Verify NumPy Installation · Step...
Read more >
How To Install NumPy In Python - Edureka
However, pip is not installed. If you want the complete package, download python from python.org and install it on your ubuntu operating system ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found