在命名行输入:
pipenv install
创建python虚拟环境
发现报错了,报错信息如下:
$ pipenv install
Creating a virtualenv for this project▒▒
Pipfile: H:\watchlist\Pipfile
Using f:\python\python.exe (3.6.5) to create virtualenv▒▒
[=== ] Creating virtual environment...Already using interpreter f:\python\python.exe
Using base prefix 'f:\\python'
New python executable in C:\Users\ѩ▒▒\.virtualenvs\watchlist-pdgJS0-f\Scripts\python.exe
Installing setuptools, pip, wheel...
done.
Failed creating virtual environment
[pipenv.exceptions.VirtualenvCreationException]: File "f:\python\lib\site-packages\pipenv\cli\command.py", line 254, in install
[pipenv.exceptions.VirtualenvCreationException]: editable_packages=state.installstate.editables,
[pipenv.exceptions.VirtualenvCreationException]: File "f:\python\lib\site-packages\pipenv\core.py", line 1741, in do_install
[pipenv.exceptions.VirtualenvCreationException]: pypi_mirror=pypi_mirror,
[pipenv.exceptions.VirtualenvCreationException]: File "f:\python\lib\site-packages\pipenv\core.py", line 574, in ensure_project
[pipenv.exceptions.VirtualenvCreationException]: pypi_mirror=pypi_mirror,
[pipenv.exceptions.VirtualenvCreationException]: File "f:\python\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 "f:\python\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 "f:\python\lib\site-packages\virtualenv.py", line 939, in call_subprocess
line = line.decode(encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd4 in position 40: invalid continuation byte
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "f:\python\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "f:\python\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "f:\python\lib\site-packages\virtualenv.py", line 2635, in
main()
File "f:\python\lib\site-packages\virtualenv.py", line 870, in main
symlink=options.symlink,
File "f:\python\lib\site-packages\virtualenv.py", line 1173, in create_environment
install_wheel(to_install, py_executable, search_dirs, download=download)
File "f:\python\lib\site-packages\virtualenv.py", line 1019, in install_wheel
_install_wheel_with_search_dir(download, project_names, py_executable, search_dirs)
File "f:\python\lib\site-packages\virtualenv.py", line 1110, in _install_wheel_with_search_dir
call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=script)
File "f:\python\lib\site-packages\virtualenv.py", line 941, in call_subprocess
line = line.decode(fs_encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd4 in position 40: invalid continuation byte
Failed to create virtual environment.
在stackoverflow上看到了一个解决方法,测试后成功创建虚拟环境
具体方法如下:
在你的python 包安装路径下找到文件:(也可以通过报错信息找到文件路径)
F:\Python\Lib\site-packages\virtualenv.py
用文本编辑工具打开修改:
将第933、934行的(可能不是在933行,只要找到这两行代码就行)
encoding = sys.getdefaultencoding()
fs_encoding = sys.getfilesystemencoding()
修改为:
encoding = sys.getdefaultencoding()
fs_encoding = 'OEM' #sys.getfilesystemencoding()
即可。
然后再次命令行输入:
pipenv install
等待几秒后创建环境成功!
此解决方法未经多次测试,不具备普遍适用性!