如何在linux min上修复python3安装

2024-05-20 21:00:17 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我使用LinuxMintMate已经有一段时间了,一切正常。 因此,当我得到一个新笔记本时,我在Windows10旁边安装了新版本的LinuxMint(19.2-Tina)。我想一切都很顺利。你知道吗

现在,我正试图让它准备好使用,但它不起作用。你知道吗

据称,它附带了两个版本的python:

  • Python 2.7.15+
  • Python 3.6.8版

但是当我试着运行一个简单的helloworld时,却为我导入了一些基本包,比如

import numpy as np
import math #as ma
import matplotlib.pyplot as plt; plt.switch_backend('agg')
import sys
import pandas as pd
import seaborn as sns; sns.set()
import powerlaw as pl
from itertools import zip_longest
import csv
import os

print('hello world')

它甚至不认识numpy包,我得到了以下信息:

Traceback (most recent call last):
  File "testes.py", line 1, in <module>
    import numpy as np
ModuleNotFoundError: No module named 'numpy'

所以我去了这个网站,并尝试遵循教程

https://packaging.python.org/tutorials/installing-packages/#id18

但当我试图安装numpy时,结果如下:

(tutorial_env) jheniffer@jheniffer-5480:~/Dropbox/teste_cros_bi$ pip install python3-numpy
Collecting python3-numpy
Exception:
Traceback (most recent call last):
  File "/home/jheniffer/Dropbox/teste_cros_bi/tutorial_env/lib/python3.6/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/home/jheniffer/Dropbox/teste_cros_bi/tutorial_env/lib/python3.6/site-packages/pip/commands/install.py", line 353, in run
    wb.build(autobuilding=True)
  File "/home/jheniffer/Dropbox/teste_cros_bi/tutorial_env/lib/python3.6/site-packages/pip/wheel.py", line 749, in build
    self.requirement_set.prepare_files(self.finder)
  File "/home/jheniffer/Dropbox/teste_cros_bi/tutorial_env/lib/python3.6/site-packages/pip/req/req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/home/jheniffer/Dropbox/teste_cros_bi/tutorial_env/lib/python3.6/site-packages/pip/req/req_set.py", line 554, in _prepare_file
    require_hashes
  File "/home/jheniffer/Dropbox/teste_cros_bi/tutorial_env/lib/python3.6/site-packages/pip/req/req_install.py", line 278, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/home/jheniffer/Dropbox/teste_cros_bi/tutorial_env/lib/python3.6/site-packages/pip/index.py", line 465, in find_requirement
    all_candidates = self.find_all_candidates(req.name)
  File "/home/jheniffer/Dropbox/teste_cros_bi/tutorial_env/lib/python3.6/site-packages/pip/index.py", line 423, in find_all_candidates
    for page in self._get_pages(url_locations, project_name):
  File "/home/jheniffer/Dropbox/teste_cros_bi/tutorial_env/lib/python3.6/site-packages/pip/index.py", line 568, in _get_pages
    page = self._get_page(location)
  File "/home/jheniffer/Dropbox/teste_cros_bi/tutorial_env/lib/python3.6/site-packages/pip/index.py", line 683, in _get_page
    return HTMLPage.get_page(link, session=self.session)
  File "/home/jheniffer/Dropbox/teste_cros_bi/tutorial_env/lib/python3.6/site-packages/pip/index.py", line 795, in get_page
    resp.raise_for_status()
  File "/home/jheniffer/Dropbox/teste_cros_bi/tutorial_env/share/python-wheels/requests-2.18.4-py2.py3-none-any.whl/requests/models.py", line 935, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://pypi.org/simple/python3-numpy/

我不知道该怎么做才能让它运转起来, 我应该如何继续安装所有的东西,因为我认为基本的软件包,比如numpy,已经安装好了,而每隔一次我尝试通过pip(在我以前的笔记本电脑上)安装一些东西时,它就可以工作了

pip3 install python3-numpy

我尝试了没有pip的选项,它安装成功了

(tutorial_env) jheniffer@jheniffer-5480:~/Dropbox/teste_cros_bi$ sudo apt install python3-numpy
[sudo] password for jheniffer:             
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  gfortran python-numpy-doc python3-dev python3-nose python3-numpy-dbg
The following NEW packages will be installed:
  python3-numpy
0 upgraded, 1 newly installed, 0 to remove and 287 not upgraded.
Need to get 1.943 kB of archives.
After this operation, 10,9 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu bionic/main amd64 python3-numpy amd64 1:1.13.3-2ubuntu1 [1.943 kB]
Fetched 1.943 kB in 4s (528 kB/s)          
Selecting previously unselected package python3-numpy.
(Reading database ... 308507 files and directories currently installed.)
Preparing to unpack .../python3-numpy_1%3a1.13.3-2ubuntu1_amd64.deb ...
Unpacking python3-numpy (1:1.13.3-2ubuntu1) ...
Setting up python3-numpy (1:1.13.3-2ubuntu1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...

但是当我试着运行hello word代码时,我又收到了这个消息

(tutorial_env) jheniffer@jheniffer-5480:~/Dropbox/teste_cros_bi$ python3 testes.py 
Traceback (most recent call last):
  File "testes.py", line 1, in <module>
    import numpy as np
ModuleNotFoundError: No module named 'numpy'



Tags: pipinpynumpyenvpackageslinetutorial
1条回答
网友
1楼 · 发布于 2024-05-20 21:00:17

看起来您可能在pip中使用了apt包名,而不是PyPi包的名称。首先,检查系统上pip和python的默认版本。这可以使用pip versionpython version来完成。如果两者都默认为python2.7(很可能是这样),我强烈建议尽可能使用python3.6,因为python2.7将在2020年达到EOL。你知道吗

您可以通过命令行使用pip3python3来显式地实现这一点。要安装用于python3的numpy,请使用pip3 install numpy。请记住,这将只为Python3安装它,因此如果您启动Python2.7解释器,它将不会被安装。你知道吗

将来,如果您想找到要安装的PyPi包的名称,可以执行pip search {QUERY},例如pip search numpy。你知道吗

相关问题 更多 >