提问者:小点点

从python 3.7更新到3.8会导致VS代码中的pylint和其他模块出现问题


我正在通过linuxbrew使用python3,今天似乎有一个关键的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版本。奇怪的是,创建了两个文件夹:

  1. /home/linuxbrew/. linuxbrew/lib/python3.8
  2. /home/linuxbrew/. linuxbrew/Cellar/python@3.8 /3.8.3_2/lib/python3.8

作为新python3中的站点包。8文件夹相当空,我移动了所有的网站包(

此外,我还认为该站点的包位于/home/linuxbrew/。利努克斯啤酒/酒窖/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

接下来,通过Ctrl-Alt P在VS代码中执行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)

另外,在VS Code的settings.json文件中,我声明了以下安全策略:

"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"

所有这些问题让我完全措手不及,我感到完全迷失了方向。我今天想继续我的项目,但已经花了2个小时在互联网上发现所有建议的解决方案都不适合我,所以我在这里开始了这个问题。


共1个答案

匿名用户

上述问题的解决方案是,需要先卸载导致问题的每个模块/包,然后从头开始重新安装。

这显然不同于简单地尝试更新已经错误安装的包。

我推测这是由于移动安装在/…中的python站点包造成的/蟒蛇3。7/站点包到新的//蟒蛇3。8/站点包手动目录。显然,并不是所有的软件包都能正常工作,需要卸载和重新安装,而不是仅仅更新。

更详细地说,我做了pip卸载Packagename,然后是pip安装Packagename,每个包都会导致问题,幸运的是不到10个。

而不是使用pip安装python3-mpip安装如果这样做效果更好,或者pip二进制文件在某种程度上被破坏了,就像我最初的情况一样(参见上面的问题)。

在通过所描述的解决方法解决了问题之后,自然会出现一个后续问题,即如何将站点包更优雅地迁移到新的python 3。x版本。