我正在通过python3
通过linuxbrew
使用linuxbrew
,今天似乎出现了一个关键的python更新,将python3.7替换为3.8。
至于我的操作系统(Lubuntu 18.04 LTS):
Operating System: Ubuntu 18.04.4 LTS
Kernel: Linux 5.3.0-62-generic
Architecture: x86-64
这就是为什么我所有python站点包的pip升级都不起作用的原因:
pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U
引发的错误是:
# /home/andylu/Desktop/Shell/python_package_complete_update_via_homebrew_n_pip: /home/linuxbrew/.linuxbrew/bin/pip: /home/linuxbrew/.linuxbrew/opt/python/bin/python3.7: bad interpreter: No such file or directory
# WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
# Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
# To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
# Defaulting to user installation because normal site-packages is not writeable
# ERROR: You must give at least one requirement to install (see "pip help install")
后来,我发现有一个新的python版本安装。奇怪的是,创建了两个文件夹:
/home/linuxbrew/.linuxbrew/lib/python3.8
/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.3_2/lib/python3.8
由于新python3.8文件夹中的站点包非常空,所以我将所有站点包(> 1GB)从残留的python3.7移到了新的python3.8文件夹。有了这个,我假设它们在python3.8下也能正常工作,而不是全部删除和重新安装。
此外,我认为/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.3_2/lib/python3.8
中的站点包似乎仅仅是指向/home/linuxbrew/.linuxbrew/lib/python3.8
下的文件夹的链接。
然后,我更新了pip包更新命令如下:
python3 -m pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 python3 -m pip install -U
这似乎很管用。然而,在打开VS Code时,它总是在右下角的“pylint linter的路径无效”中声明,即使路径存在:
USER:~/Desktop/Python/Scripts$ which pylint
/home/linuxbrew/.linuxbrew/bin/pylint
USER:~/Desktop/Python/Scripts$ which python
/usr/bin/python
USER:~/Desktop/Python/Scripts$ which python3
/home/linuxbrew/.linuxbrew/bin/python3
接下来,在VS代码中通过Ctrl + Alt +P执行python-脚本时,会发生以下错误(以及整个输出):
USER:~/Desktop/Python/Scripts$
/home/linuxbrew/.linuxbrew/bin/python3 -c "from IPython import start_ipython; start_ipython()" /home/cripts/Master/Import_export/AERMET/import_and_manip_sitespec_meteodata_AERMET.py
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/numpy/core/__init__.py in <module>
21 try:
---> 22 from . import multiarray
23 except ImportError as exc:
/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/numpy/core/multiarray.py in <module>
11
---> 12 from . import overrides
13 from . import _multiarray_umath
/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/numpy/core/overrides.py in <module>
6
----> 7 from numpy.core._multiarray_umath import (
8 add_docstring, implement_array_function, _get_implementing_args)
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
During handling of the above exception, another exception occurred:
ImportError Traceback (most recent call last)
~/Dokumente/Allgemeines_material/Sonstiges/Programming/Python/Scripts/Master/Import_export/AERMET/import_and_manip_sitespec_meteodata_AERMET.py in <module>
40
41 import re
---> 42 import numpy as np
43 import pandas as pd
44 from tqdm import tqdm
/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/numpy/__init__.py in <module>
138 from . import _distributor_init
139
--> 140 from . import core
141 from .core import *
142 from . import compat
/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages/numpy/core/__init__.py in <module>
46 """ % (sys.version_info[0], sys.version_info[1], sys.executable,
47 __version__, exc)
---> 48 raise ImportError(msg)
49 finally:
50 for envkey in env_added:
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.8 from "/home/linuxbrew/.linuxbrew/opt/python@3.8/bin/python3.8"
* The NumPy version is: "1.19.0"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named 'numpy.core._multiarray_umath'
然而,numpy
已经是最新的了:
USER:~/Desktop/Python/Scripts$ pip install numpy
Requirement already satisfied: numpy in /home/linuxbrew/.linuxbrew/lib/python3.8/site-packages (1.19.0)
另外,在settings.json
的VS Code
文件中,我声明了以下操作的安全性:
"python.autoComplete.extraPaths": [
"/home/andylu/Dokumente/Allgemeines_material/Sonstiges/Programming/Python/Scripts",
"/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages",
"/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.3_2/lib/python3.8/site-packages"
]
在我的.bashrc文件中,我已经更新了所有内容,但没有结果:
# Link to own and official python scripts and packages
export PYTHONPATH=/home/andylu/Dokumente/Allgemeines_material/Sonstiges/Programming/Python/Scripts:/home/linuxbrew/.linuxbrew/lib/python3.8/site-packages:/home/linuxbrew/.linuxbrew/Cellar/python@3.8/3.8.3_2/lib/python3.8/site-packages
# Homebrew
export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"
所有这些问题都让我措手不及,我感到完全不知所措。我今天想继续我的项目,但是已经花了两个小时在互联网上,发现所提出的解决方案中没有一个对我有用,所以我在这里开始了这个问题。
发布于 2020-07-14 08:59:26
上述问题的解决方案是,首先需要卸载每个导致问题的模块/包,然后从零开始重新安装。
这显然不同于简单地试图更新已经错误安装的软件包。
我认为这是由于手动将安装在/../python3.7/site-packages
中的python包移动到新的/../python3.8/site-packages
目录造成的。显然,并不是所有的软件包都能很好地运行,并且需要卸载和重新安装,而不是仅仅更新。
更详细地说,我使用了pip uninstall packagename
和pip install packagename
,每个包都会导致问题,幸运的是,不到10个包。
与使用pip install ...
不同,还可以使用python3 -m pip install ...
,如果这样做更好,或者pip-二进制文件以某种方式损坏,这是我最初的情况(见上面的问题)。
在通过所描述的解决方法解决了这些问题之后,自然就出现了一个关于如何将站点-包更优雅地迁移到新的python3.x版本的follow-up question。
https://stackoverflow.com/questions/62880270
复制相似问题