9

我正在尝试在 pycharm edu 上安装 dotenv 包,但不断收到错误消息:“AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'”

我尝试使用python终端通过以root用户身份运行命令“pip install --user dotenv”来解决这个问题,但仍然遇到同样的错误

命令输出内容如下

Collecting dotenv
Using cached https://files.pythonhosted.org/packages/e2/46/3754073706e31670eed18bfa8a879305b56a471db15f20523c2427b10078/dotenv-0.0.5.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 154, in save_modules
    yield saved
  File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 194, in setup_context
    __import__('setuptools')
  File "/tmp/easy_install-vzgpp8in/distribute-0.7.3/setuptools/__init__.py", line 2, in <module>
  File "/tmp/easy_install-vzgpp8in/distribute-0.7.3/setuptools/extension.py", line 5, in <module>
  File "/tmp/easy_install-vzgpp8in/distribute-0.7.3/setuptools/dist.py", line 7, in <module>
  File "/tmp/easy_install-vzgpp8in/distribute-0.7.3/setuptools/command/__init__.py", line 8, in <module>
  File "/tmp/easy_install-vzgpp8in/distribute-0.7.3/setuptools/command/install_scripts.py", line 3, in <module>
  File "/tmp/easy_install-vzgpp8in/distribute-0.7.3/pkg_resources.py", line 1518, in <module>
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/pycharm-packaging11/dotenv/setup.py", line 23, in <module>
    scripts=['scripts/dotenv']
  File "/usr/lib/python3.6/distutils/core.py", line 108, in setup
    _setup_distribution = dist = klass(attrs)
  File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 269, in __init__
    self.fetch_build_eggs(attrs['setup_requires'])
  File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 313, in fetch_build_eggs
    replace_conflicting=True,
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 826, in resolve
    dist = best[req.key] = env.best_match(req, ws, installer)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1092, in best_match
    return self.obtain(req, installer)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1104, in obtain
    return installer(requirement)
  File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 380, in fetch_build_egg
    return cmd.easy_install(req)
  File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 663, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 693, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 873, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 1101, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 1087, in run_setup
    run_setup(setup_script, args)
  File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 233, in run_setup
    with setup_context(setup_dir):
  File "/usr/lib/python3.6/contextlib.py", line 81, in __enter__
    return next(self.gen)
  File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 195, in setup_context
    yield
  File "/usr/lib/python3.6/contextlib.py", line 99, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 166, in save_modules
    saved_exc.resume()
  File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 141, in resume
    six.reraise(type, exc, self._tb)
  File "/usr/lib/python3/dist-packages/pkg_resources/_vendor/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 154, in save_modules
    yield saved
  File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 194, in setup_context
    __import__('setuptools')
  File "/tmp/easy_install-vzgpp8in/distribute-0.7.3/setuptools/__init__.py", line 2, in <module>
  File "/tmp/easy_install-vzgpp8in/distribute-0.7.3/setuptools/extension.py", line 5, in <module>
  File "/tmp/easy_install-vzgpp8in/distribute-0.7.3/setuptools/dist.py", line 7, in <module>
  File "/tmp/easy_install-vzgpp8in/distribute-0.7.3/setuptools/command/__init__.py", line 8, in <module>
  File "/tmp/easy_install-vzgpp8in/distribute-0.7.3/setuptools/command/install_scripts.py", line 3, in <module>
  File "/tmp/easy_install-vzgpp8in/distribute-0.7.3/pkg_resources.py", line 1518, in <module>
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'

----------------------------------------

命令“python setup.py egg_info”失败,错误代码 1 在 /tmp/pycharm-packaging11/dotenv/”

4

2 回答 2

35

尝试安装“python-dotenv”包而不是“dotenv”。这应该可以解决问题。

sudo pip install python-dotenv

在此处输入图像描述] 1

于 2019-05-09T10:54:07.273 回答
0

安装python-dotenv然后导入dotenv包而不是python-dotenv,因为后者不起作用

于 2021-08-06T05:39:41.463 回答