简体   繁体   English

即使安装后也没有名为numpy的模块

[英]no module named numpy even after installing it

I am using numpy in a python file. 我在python文件中使用numpy。 I am trying to execut this file on a remote linux server. 我正在尝试在远程linux服务器上执行此文件。 I have installed pip and numpy without being root as mentioned in this post: https://gist.github.com/saurabhshri/46e4069164b87a708b39d947e4527298 我已经安装了pipnumpy而不是本帖子中提到的root用户: https : //gist.github.com/saurabhshri/46e4069164b87a708b39d947e4527298

Despite the fact that pip and numpy were both installed successfully I still get : 尽管pip和numpy都已成功安装,但我仍然得到:

import numpy

 ModuleNotFoundError: No module named 'numpy'

I have tried to create a virtual environment but when doing that I get: 我试图创建一个虚拟环境,但是这样做的时候我得到了:

File "/usr/local/bin/pip", line 7, in <module>
    from pip import main
ImportError: cannot import name main 

ps: when I type ./pip list this is the main stuff I get: ps:当我输入./pip list这是我得到的主要内容:

numpy              1.16.3 
pip                19.1.1

and I have both: Python 2.7.15rc1 and Python 3.6.7 和我都有: Python 2.7.15rc1Python 3.6.7

You should check if you installed NumPy for Python version you actually try to use. 您应该检查您是否安装了实际尝试使用的NumPy for Python版本。 The easiest way is to list two directories: 最简单的方法是列出两个目录:

  • ls -la ~/.local/lib/python2.7/site-packages/
  • ls -la ~/.local/lib/python3.5/site-packages/

and check if there are NumPy files (directories may differ due to your version of Python). 并检查是否有NumPy文件(目录可能因您的Python版本而异)。 If there are none, you may want to install them: 如果没有,则可能要安装它们:

Python 2.x: Python 2.x:

  1. wget https://bootstrap.pypa.io/get-pip.py
  2. python get-pip.py --user
  3. echo "PATH=\\$PATH:~/.local/bin" >> ~/.bashrc
  4. source ~/.bashrc
  5. pip install numpy --user

Python 3.x: Python 3.x:

  1. wget https://bootstrap.pypa.io/get-pip.py
  2. python3 get-pip.py --user
  3. echo "PATH=\\$PATH:~/.local/bin" >> ~/.bashrc
  4. source ~/.bashrc
  5. pip3 install numpy --user

the 3rd command should be : 第三个命令应该是:

echo "export PATH=~/.local/bin:$PATH" >> ~/.bashrc

bash should use pip from ~/.local/bin, not from /usr/local/bin. bash应该使用〜/ .local / bin中的pip,而不是/ usr / local / bin中的pip。 So I placed .local before every other entry in the path. 所以我将.local放在路径中的所有其他条目之前。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM