Pycharm找不到包的问题

问题描述 投票:0回答:1

我在pycharm中运行一段代码时遇到了多个问题。因为我是学生,而且我使用的是受版权保护的代码,所以我不能在这里分享,但我可以向你保证,这与代码无关。

每当我尝试运行代码时,我都会得到以下错误。

`ModuleNotFoundError: No module named 'apt_pkg'`
`ModuleNotFoundError: No module named 'numpy'`

我已经安装了numpy for python 3.8,并且在包解释器中也有显示,但是Pycharm一直试图运行我的代码。/usr/bin/python3.7 出于某种原因,即使我的系统解释器设置为 Python 3.8。

我也试过在 3.8 中用 venv 运行代码。还是同样的错误。

现在,当我尝试将我的解释器设置为Python 3.7时,无论是系统解释器还是venv,我都得到numpy未安装的消息。

当我试图安装numpy指定Python 3.7时。

/usr/bin/python3.7 -m pip install numpy

我得到了以下错误。

Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3/dist-packages/pip/__main__.py", line 16, in <module>
    from pip._internal.cli.main import main as _main  # isort:skip # noqa
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 10, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
    from pip._internal.cli import cmdoptions
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/cmdoptions.py", line 19, in <module>
    from distutils.util import strtobool
ModuleNotFoundError: No module named 'distutils.util'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
    from apport.packaging_impl import impl as packaging
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 23, in <module>
    import apt
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3/dist-packages/pip/__main__.py", line 16, in <module>
    from pip._internal.cli.main import main as _main  # isort:skip # noqa
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 10, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
    from pip._internal.cli import cmdoptions
  File "/usr/lib/python3/dist-packages/pip/_internal/cli/cmdoptions.py", line 19, in <module>
    from distutils.util import strtobool
ModuleNotFoundError: No module named 'distutils.util'

我试着安装 distutils.util,但我一直得到同样的错误信息。

是不是Python 3.7有什么问题?有没有办法告诉pycharm不要在Python 3.7中运行?

我还想补充一点,我已经尝试过从头开始重新安装所有东西,包括 Ubuntu。

我使用的是Ubuntu 20.04。

python pycharm
1个回答
0
投票

谢谢你的回答,我通过删除所有解释器并从头设置,现在设法解决了这个问题。

可能是多个解释器和不同的python版本之间存在某种冲突。

© www.soinside.com 2019 - 2024. All rights reserved.