Pycharm找不到软件包的问题

时间:2020-05-02 12:02:34

标签: python pycharm

在pycharm中运行代码时遇到多个问题。由于我是学生,并且使用的是受版权保护的代码,因此无法在此处共享它,但可以向您保证,它与代码无关。

每当我尝试运行代码时,都会出现以下错误:

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

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

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

现在,当我尝试将解释器设置为Python 3.7(系统解释器和venv)时,我得到未安装numpy。

当我尝试安装指定python 3.7的numpy时:

/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。

1 个答案:

答案 0 :(得分:0)

谢谢您的回答,我设法通过删除所有解释程序并从头开始进行设置来解决此问题。

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