Windows11下pip安装dotenv模块失败问题求助
解决Windows 11下pip安装dotenv模块失败的问题
报错信息
执行pip install dotenv时出现以下错误:
pip install dotenv Collecting dotenv Using cached dotenv-0.0.5.tar.gz (2.4 kB) Preparing metadata (setup.py) ... error error: subprocess-exited-with-error × python setup.py egg_info did not run successfully. │ exit code: 1 ╰─> [67 lines of output] C:\Users\tolga\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\setuptools\installer.py:27: SetuptoolsDeprecationWarning: setuptools.installer is deprecated. Requirements should be satisfied by a PEP 517 installer. warnings.warn( WARNING: The wheel package is not available. error: subprocess-exited-with-error python setup.py egg_info did not run successfully. exit code: 1 [16 lines of output] Traceback (most recent call last): File "<string>", line 2, in <module> File "<pip-setuptools-caller>", line 14, in <module> File "C:\Users\tolga\AppData\Local\Temp\pip-wheel-aje7yoko\distribute_df22646f998648fc97a3f7928dd4b26e\setuptools\__init__.py", line 2, in <module> from setuptools.extension import Extension, Library File "C:\Users\tolga\AppData\Local\Temp\pip-wheel-aje7yoko\distribute_df22646f998648fc97a3f7928dd4b26e\setuptools\extension.py", line 5, in <module> from setuptools.dist import _get_unpatched File "C:\Users\tolga\AppData\Local\Temp\pip-wheel-aje7yoko\distribute_df22646f998648fc97a3f7928dd4b26e\setuptools\dist.py", line 7, in <module> from setuptools.command.install import install File "C:\Users\tolga\AppData\Local\Temp\pip-wheel-aje7yoko\distribute_df22646f998648fc97a3f7928dd4b26e\setuptools\command\__init__.py", line 8, in <module> from setuptools.command import install_scripts File "C:\Users\tolga\AppData\Local\Temp\pip-wheel-aje7yoko\distribute_df22646f998648fc97a3f7928dd4b26e\setuptools\command\install_scripts.py", line 3, in <module> from pkg_resources import Distribution, PathMetadata, ensure_directory File "C:\Users\tolga\AppData\Local\Temp\pip-wheel-aje7yoko\distribute_df22646f998648fc97a3f7928dd4b26e\pkg_resources.py", line 1518, in <module> register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider) AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader' [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed Encountered error while generating package metadata. See above for output. note: This is an issue with the package mentioned above, not pip. hint: See above for details. Traceback (most recent call last): File "C:\Users\tolga\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\setuptools\installer.py", line 82, in fetch_build_egg subprocess.check_call(cmd) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 369, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '["C:\\Users\\tolga\\AppData\\Local\\Microsoft\\WindowsApps\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\python.exe", "-m", "pip", "--disable-pip-version-check", "wheel", "--no-deps", "-w", "C:\\Users\\tolga\\AppData\\Local\\Temp\\tmpu566_0w9", "--quiet", "distribute"]' returned non-zero exit status 1. The above exception was the direct cause of the following exception: Traceback (most recent call last): File "<string>", line 2, in <module> File "<pip-setuptools-caller>", line 34, in <module> File "C:\Users\tolga\AppData\Local\Temp\pip-install-6o_73kl2\dotenv_b003414150d042bd85e84e2ed2f8252e\setup.py", line 13, in <module> setup(name='dotenv', File "C:\Users\tolga\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\setuptools\__init__.py", line 86, in setup _install_setup_requires(attrs) File "C:\Users\tolga\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\setuptools\__init__.py", line 80, in _install_setup_requires dist.fetch_build_eggs(dist.setup_requires) File "C:\Users\tolga\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\setuptools\dist.py", line 875, in fetch_build_eggs resolved_dists = pkg_resources.working_set.resolve( File "C:\Users\tolga\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pkg_resources\__init__.py", line 789, in resolve dist = best[req.key] = env.best_match( File "C:\Users\tolga\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pkg_resources\__init__.py", line 1075, in best_match return self.obtain(req, installer) File "C:\Users\tolga\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pkg_resources\__init__.py", line 1087, in obtain return installer(requirement) File "C:\Users\tolga\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\setuptools\dist.py", line 945, in fetch_build_egg return fetch_build_egg(self, req) File "C:\Users\tolga\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\setuptools\installer.py", line 84, in fetch_build_egg raise DistutilsError(str(e)) from e distutils.errors.DistutilsError: Command '["C:\\Users\\tolga\\AppData\\Local\\Microsoft\\WindowsApps\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\python.exe", "-m", "pip", "--disable-pip-version-check", "wheel", "--no-deps", "-w", "C:\\Users\\tolga\\AppData\\Local\\Temp\\tmpu566_0w9", "--quiet", "distribute"]' returned non-zero exit status 1. [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. error: metadata-generation-failed × Encountered error while generating package metadata. ╰─> See above for output. note: This is an issue with the package mentioned above, not pip. hint: See above for details.
已尝试操作
已执行以下命令升级pip和setuptools,但问题未解决:
python -m pip install --upgrade pip pip install --upgrade setuptools
问题根源
你尝试安装的dotenv是一个废弃多年的老旧包(版本0.0.5,最后更新于2013年),它依赖的distribute包与Python 3.10完全不兼容,导致出现AttributeError错误。目前主流的环境变量加载包是python-dotenv,而非这个老旧的dotenv。
解决方案
- 卸载错误的老旧包(如果已安装):
pip uninstall -y dotenv
- 安装正确的包:
pip install python-dotenv
- 验证安装:
打开Python交互环境,执行以下代码测试:
from dotenv import load_dotenv # 如果没有报错,说明安装成功
内容的提问来源于stack exchange,提问作者Tolga
相关产品推荐
相关产品推荐

