Pipenv 创建虚拟环境报错 ModuleNotFoundError: No module named 'pkgutil'


Windows环境下,使用pipenv创建虚拟环境失败

请使用纯文本给出完整的错误输出。另外,建议在 Windows 下使用 Poetry 替代 Pipenv,用法差不多。

C:\Users\xl>cd Desktop

C:\Users\xl\Desktop>cd helloflask

C:\Users\xl\Desktop\helloflask>pipenv install
Creating a virtualenv for this project…
Pipfile: C:\Users\xl\Desktop\helloflask\Pipfile
Using c:\users\xl\appdata\local\programs\python\python36\python.exe (3.6.5) to create virtualenv…
[    ] Creating virtual environment...Already using interpreter c:\users\xl\appdata\local\programs\python\python36\python.exe
Using base prefix 'c:\\users\\xl\\appdata\\local\\programs\\python\\python36'
New python executable in D:\Python virtual\helloflask-VxfPPwJQ\Scripts\python.exe
Command "D:\Python virtual\he...Q\Scripts\python.exe" -m pip config list had error code 1
Installing setuptools, pip, wheel...

  Complete output from command "D:\Python virtual\he...Q\Scripts\python.exe" - setuptools pip wheel:
  Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
ModuleNotFoundError: No module named 'pkgutil'
----------------------------------------
...Installing setuptools, pip, wheel...done.

Failed creating virtual environment
[pipenv.exceptions.VirtualenvCreationException]:   File "c:\users\xl\appdata\local\programs\python\python36\lib\site-packages\pipenv\cli\command.py", line 254, in install
[pipenv.exceptions.VirtualenvCreationException]:       editable_packages=state.installstate.editables,
[pipenv.exceptions.VirtualenvCreationException]:   File "c:\users\xl\appdata\local\programs\python\python36\lib\site-packages\pipenv\core.py", line 1741, in do_install
[pipenv.exceptions.VirtualenvCreationException]:       pypi_mirror=pypi_mirror,
[pipenv.exceptions.VirtualenvCreationException]:   File "c:\users\xl\appdata\local\programs\python\python36\lib\site-packages\pipenv\core.py", line 574, in ensure_project
[pipenv.exceptions.VirtualenvCreationException]:       pypi_mirror=pypi_mirror,
[pipenv.exceptions.VirtualenvCreationException]:   File "c:\users\xl\appdata\local\programs\python\python36\lib\site-packages\pipenv\core.py", line 506, in ensure_virtualenv
[pipenv.exceptions.VirtualenvCreationException]:       python=python, site_packages=site_packages, pypi_mirror=pypi_mirror
[pipenv.exceptions.VirtualenvCreationException]:   File "c:\users\xl\appdata\local\programs\python\python36\lib\site-packages\pipenv\core.py", line 935, in do_create_virtualenv
[pipenv.exceptions.VirtualenvCreationException]:       extra=[crayons.blue("{0}".format(c.err)),]
[pipenv.exceptions.VirtualenvCreationException]: Traceback (most recent call last):
  File "c:\users\xl\appdata\local\programs\python\python36\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\xl\appdata\local\programs\python\python36\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\users\xl\appdata\local\programs\python\python36\lib\site-packages\virtualenv.py", line 2567, in <module>
    main()
  File "c:\users\xl\appdata\local\programs\python\python36\lib\site-packages\virtualenv.py", line 793, in main
    symlink=options.symlink,
  File "c:\users\xl\appdata\local\programs\python\python36\lib\site-packages\virtualenv.py", line 1088, in create_environment
    install_wheel(to_install, py_executable, search_dirs, download=download)
  File "c:\users\xl\appdata\local\programs\python\python36\lib\site-packages\virtualenv.py", line 935, in install_wheel
    _install_wheel_with_search_dir(download, project_names, py_executable, search_dirs)
  File "c:\users\xl\appdata\local\programs\python\python36\lib\site-packages\virtualenv.py", line 1025, in _install_wheel_with_search_dir
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=script)
  File "c:\users\xl\appdata\local\programs\python\python36\lib\site-packages\virtualenv.py", line 886, in call_subprocess
    raise OSError("Command {} failed with error code {}".format(cmd_desc, proc.returncode))
OSError: Command "D:\Python virtual\he...Q\Scripts\python.exe" - setuptools pip wheel failed with error code 1

Failed to create virtual environment.

感谢您的回答,上面是完整的提示信息,不知道能否有办法解决一下。谢谢

不太清楚怎么解决,可以按提示试试安装没找到的 pkgutil 库:

$ pip install pkgutil
C:\Users\xl>pip install pkgutil
Collecting pkgutil
  Could not find a version that satisfies the requirement pkgutil (from versions: )
No matching distribution found for pkgutil

已经尝试过,但提示找不到

搜了一下,这个库是标准库从 2.3 内置的,忽略上一条建议。可以依次试试下面这些方法:

  • 使用 python -m pipenv install 命令
  • 去掉路径里的中文(这会引起很多错误),也就是把你的 Windows 系统用户名改成英文
  • 重装 Python

好的,辛苦了。等我一一尝试再回复你结果,谢谢^_^。

1 个赞

通过将用户名改为英文以及重装python,已经成功解决。感谢