我正在尝试为Mac上的Python项目创建虚拟环境。
我创建了以下变量:
python3 -m venv venv
当我尝试运行时:
virtualenv venv
我收到以下错误:
zsh: /usr/local/bin/virtualenv: bad interpreter: /usr/local/opt/python3/bin/python3.6: no such file or directory
Using base prefix '/Users/<user_name>/miniconda3'
New python executable in /Users/<user_name>/something/venv/bin/python3
Traceback (most recent call last):
File "/Users/<user_name>/miniconda3/bin/virtualenv", line 10, in <module>
sys.exit(main())
File "/Users/<user_name>/miniconda3/lib/python3.6/site-packages/virtualenv.py", line 831, in main
symlink=options.symlink,
File "/Users/<user_name>/miniconda3/lib/python3.6/site-packages/virtualenv.py", line 1106, in create_environment
install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages=site_packages, clear=clear, symlink=symlink)
File "/Users/<user_name>/miniconda3/lib/python3.6/site-packages/virtualenv.py", line 1473, in install_python
shutil.copyfile(executable, py_executable)
File "/Users/<user_name>/miniconda3/lib/python3.6/shutil.py", line 104, in copyfile
raise SameFileError("{!r} and {!r} are the same file".format(src, dst))
shutil.SameFileError: '/Users/<user_name>/miniconda3/bin/python3' and '/Users/<user_name>/something/venv/bin/python3' are the same file
为解决此问题,我尝试了此post中建议的方法,该方法是强制重新安装virtualevn。他们建议进行以下修复:
pip install -U --force-reinstall virtualenv
但是,another post让我意识到,以这种方式使用pip可能会出现问题。因此,我将卸载命令调整为:
python3 -m pip install -U --force-reinstall virtualenv
但是错误仍然存在。我的直觉是我将不得不进入一些文件并更改路径。但是我不确定该走哪条路,应该走什么新路。
我还签出了this post,这使我想到了如何在计算机上安装各种版本的Python和pip。结果如下:
Machine-Name-2% which python
/Users/<user_name>/miniconda3/bin/python
Machine-Name-2% which python3
/Users/<user_name>/miniconda3/bin/python3
Machine-Name-2% pip --version
pip 19.0.1 from /Users/<user_name>/miniconda3/lib/python3.6/site-packages/pip (python 3.6)
Machine-Name-2% pip3 version
ERROR: unknown command "version"
Machine-Name-2% pip3 --version
pip 19.0.1 from /Users/<user_name>/miniconda3/lib/python3.6/site-packages/pip (python 3.6)