无法在Windows上安装dotenv

9

我从来没有想过会用到Stack Overflow,但是现在我需要了!

当我在Windows上执行pip install dotenv命令并加上可选参数时,出现了以下错误:

Collecting dotenv
  Using cached dotenv-0.0.5.tar.gz (2.4 kB)
    ERROR: Command errored out with exit status 1:
     command: 'c:\python38\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Damian Freeman\\AppData\\Local\\Temp\\pip-install-bdy5mww4\\dotenv\\setup.py'"'"'; __file__='"'"'C:\\Users\\Damian Freeman\\AppData\\Local\\Temp\\pip-install-bdy5mww4\\dotenv\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\Damian Freeman\AppData\Local\Temp\pip-pip-egg-info-k9desg5s'
         cwd: C:\Users\Damian Freeman\AppData\Local\Temp\pip-install-bdy5mww4\dotenv\
    Complete output (52 lines):
    WARNING: The wheel package is not available.
        ERROR: Command errored out with exit status 1:
         command: 'c:\python38\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Damian Freeman\\AppData\\Local\\Temp\\pip-wheel-djm3svo6\\distribute\\setup.py'"'"'; __file__='"'"'C:\\Users\\Damian Freeman\\AppData\\Local\\Temp\\pip-wheel-djm3svo6\\distribute\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\Damian Freeman\AppData\Local\Temp\pip-pip-egg-info-s15217m9'
             cwd: C:\Users\Damian Freeman\AppData\Local\Temp\pip-wheel-djm3svo6\distribute\
        Complete output (15 lines):
        Traceback (most recent call last):
          File "<string>", line 1, in <module>
          File "C:\Users\Damian Freeman\AppData\Local\Temp\pip-wheel-djm3svo6\distribute\setuptools\__init__.py", line 2, in <module>
            from setuptools.extension import Extension, Library
          File "C:\Users\Damian Freeman\AppData\Local\Temp\pip-wheel-djm3svo6\distribute\setuptools\extension.py", line 5, in <module>
            from setuptools.dist import _get_unpatched
          File "C:\Users\Damian Freeman\AppData\Local\Temp\pip-wheel-djm3svo6\distribute\setuptools\dist.py", line 7, in <module>
            from setuptools.command.install import install
          File "C:\Users\Damian Freeman\AppData\Local\Temp\pip-wheel-djm3svo6\distribute\setuptools\command\__init__.py", line 8, in <module>
            from setuptools.command import install_scripts
          File "C:\Users\Damian Freeman\AppData\Local\Temp\pip-wheel-djm3svo6\distribute\setuptools\command\install_scripts.py", line 3, in <module>
            from pkg_resources import Distribution, PathMetadata, ensure_directory
          File "C:\Users\Damian Freeman\AppData\Local\Temp\pip-wheel-djm3svo6\distribute\pkg_resources.py", line 1518, in <module>
            register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
        AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
        ----------------------------------------
    ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
    Traceback (most recent call last):
      File "c:\python38\lib\site-packages\setuptools\installer.py", line 128, in fetch_build_egg
        subprocess.check_call(cmd)
      File "c:\python38\lib\subprocess.py", line 364, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['c:\\python38\\python.exe', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', 'C:\\Users\\DAMIAN~1\\AppData\\Local\\Temp\\tmpfnchk15m', '--quiet', 'distribute']' returned non-zero exit status 1.

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\Damian Freeman\AppData\Local\Temp\pip-install-bdy5mww4\dotenv\setup.py", line 13, in <module>
        setup(name='dotenv',
      File "c:\python38\lib\site-packages\setuptools\__init__.py", line 143, in setup
        _install_setup_requires(attrs)
      File "c:\python38\lib\site-packages\setuptools\__init__.py", line 138, in _install_setup_requires
        dist.fetch_build_eggs(dist.setup_requires)
      File "c:\python38\lib\site-packages\setuptools\dist.py", line 695, in fetch_build_eggs
        resolved_dists = pkg_resources.working_set.resolve(
      File "c:\python38\lib\site-packages\pkg_resources\__init__.py", line 781, in resolve
        dist = best[req.key] = env.best_match(
      File "c:\python38\lib\site-packages\pkg_resources\__init__.py", line 1066, in best_match
        return self.obtain(req, installer)
      File "c:\python38\lib\site-packages\pkg_resources\__init__.py", line 1078, in obtain
        return installer(requirement)
      File "c:\python38\lib\site-packages\setuptools\dist.py", line 754, in fetch_build_egg
        return fetch_build_egg(self, req)
      File "c:\python38\lib\site-packages\setuptools\installer.py", line 130, in fetch_build_egg
        raise DistutilsError(str(e))
    distutils.errors.DistutilsError: Command '['c:\\python38\\python.exe', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', 'C:\\Users\\DAMIAN~1\\AppData\\Local\\Temp\\tmpfnchk15m', '--quiet', 'distribute']' returned non-zero exit status 1.
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

然而,我在一篇旧的帖子上读到要使用 pip install python-dotenv 安装 DotEnv,但是这个“解决方案”对我的问题没有起作用。

任何帮助都将不胜感激!


这个回答解决了你的问题吗?[使用pip3:模块“importlib._bootstrap”没有属性“SourceFileLoader”] (https://dev59.com/KVcP5IYBdhLWcg3wLnVC) - jordanm
我不这么认为... 我能够使用相同的命令安装discord.py和其他模块。 - Damian Freeman
错误是相同的,尽管如此。 - jordanm
是的...我明白了... - Damian Freeman
你能否尝试使用 python -m pip install dotenv 命令进行安装?你的电脑上是否安装了多个版本的Python?你从哪里获取的Python安装文件(官网、Windows Store等)? - Robin De Schepper
2个回答

30

您正在安装 dotenv,而不是 python-dotenv。请使用以下命令:

pip install -U python-dotenv

请参考这个问题


如果您正在使用Python笔记本,则可以直接安装并运行笔记本单元。 - Maleehak
如果您不是,请参见此处。如果这不能解决问题,则请提出一个详细的新问题。 - Maleehak

0
我在使用Mac,这个答案帮助我解决了25分钟的问题。我执行了以下操作:pipenv lock --clear && pipenv lock --pre --clear,删除了Pipfile.lock文件,并用pipenv update替换它,然后执行pipenv install && pipenv shell,最后再次尝试pipenv install dotenv。非常感谢!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接