Python-MAC使用virtualenv建立虚拟环境

安装virtualenv

ZFJ:~ zfj$ pip install --user virtualenv
Collecting virtualenv
  Downloading https://files.pythonhosted.org/packages/b6/30/96a02b2287098b23b875bc8c2f58071c35d2efe84f747b64d523721dc2b5/virtualenv-16.0.0-py2.py3-none-any.whl (1.9MB)
    100% |████████████████████████████████| 1.9MB 19kB/s 
Installing collected packages: virtualenv
  The script virtualenv is installed in '/Users/zfj/Library/Python/2.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed virtualenv-16.0.0

注意:如果你是Linux系统,且上面的做法不管用,可以使用系统的包管理器来安装virtualenv。例如,要在Ubuntu系统中安装virtualenv,可以使用命令sudo apt-get install python-virtualenv。

切换到项目目录下,创建虚拟环境:

ZFJ:~ zfj$ cd /Users/zfj/Desktop/ZFJ_LearningLog/LearningLog 
ZFJ:LearningLog zfj$ virtualenv ll_env
-bash: virtualenv: command not found

注意:如果出现“-bash: virtualenv: command not found”这个问题,这是可以通过“find / -name virtualenv”命令找出virtualenv。

ZFJ:LearningLog zfj$ find / -name virtualenv
find: /usr/sbin/authserver: Permission denied
find: /.Spotlight-V100: Permission denied

......

find: /.DocumentRevisions-V100: Permission denied
/Users/zfj/Library/Python/2.7/bin/virtualenv
find: /Users/Guest/Music: Permission denied

......

然后再执行命令行:

ZFJ:LearningLog zfj$ /Users/zfj/Library/Python/2.7/bin/virtualenv ll_env
New python executable in /Users/zfj/Desktop/ZFJ_LearningLog/LearningLog/ll_env/bin/python
Installing setuptools, pip, wheel...
done.

激活虚拟环境,建立虚拟环境以后,需要通过下面的命令行激活:

ZFJ:LearningLog zfj$ source ll_env/bin/activate
(ll_env) ZFJ:LearningLog zfj$

这个命令行运行ll_env/bin中的脚本activate。环境处于活跃状态的时候,环境名将在括号内(ll_env)。

注意:如果你使用的是win环境,使用ll_env\Scripts\activate来激活环境。

如果要停止虚拟环境,使用下面的命令行:

(ll_env) ZFJ:LearningLog zfj$ deactivate
ZFJ:LearningLog zfj$

结束语

欢迎各位大神补充!

欢迎大家加移动开发技术交流群,在这里大家可以一起讨论学习,这里有大佬,也有小菜鸟,没事还能斗斗图装装逼,如果需要换工作的还能相互推荐,期待大家的加入!

 

python virtualenv 创建python虚拟环境时报错

08-25
windows10 + python2.7.9 在桌面创建虚拟环境的时候出现: ``` C:\Users\我们都是小怪兽\Desktop>virtualenv myenv New python executable in C:\Users\我们都是小怪兽\Desktop\myenv\Scripts\python.exe Traceback (most recent call last): File "<string>", line 1, in <module> UnicodeDecodeError: 'ascii' codec can't decode byte 0xce in position 9: ordinal not in range(128) ERROR: The executable C:\Users\我们都是小怪兽\Desktop\myenv\Scripts\python.exe is not functioning ERROR: It thinks sys.prefix is u'c:\\users\\\u6211\u4eec\u90fd\u662f\u5c0f\u602a\u517d\\desktop' (should be u'c:\\users\\\u6211\u4eec\u90fd\u662f\u5c0f\u602a\u517d\\desktop\\myenv') ERROR: virtualenv is not compatible with this system or executable Note: some Windows users have reported this error when they installed Python for "Only this user" or have multiple versions of Python installed. Copying the appropriate PythonXX.dll to the virtualenv Scripts/ directory may fix this problem. ``` 除了桌面的其他目录出现这个: ``` PS C:\> cd D:\Coding\python PS D:\Coding\python> virtualenv env New python executable in D:\Coding\python\env\Scripts\python.exe Installing setuptools, pip, wheel... Complete output from command D:\Coding\python\env\Scripts\python.exe - setuptools pip wheel: Collecting setuptools Exception: Traceback (most recent call last): File "c:\python27\lib\site-packages\virtualenv_support\pip-8.0.2-py2.py3-none-any.whl\pip\basecommand.py", line 209, in main status = self.run(options, args) File "c:\python27\lib\site-packages\virtualenv_support\pip-8.0.2-py2.py3-none-any.whl\pip\commands\install.py", line 299, in run requirement_set.prepare_files(finder) File "c:\python27\lib\site-packages\virtualenv_support\pip-8.0.2-py2.py3-none-any.whl\pip\req\req_set.py", line 359, in prepare_files ignore_dependencies=self.ignore_dependencies)) File "c:\python27\lib\site-packages\virtualenv_support\pip-8.0.2-py2.py3-none-any.whl\pip\req\req_set.py", line 576, in _prepare_file session=self.session, hashes=hashes) File "c:\python27\lib\site-packages\virtualenv_support\pip-8.0.2-py2.py3-none-any.whl\pip\download.py", line 809, in unpack_url hashes=hashes File "c:\python27\lib\site-packages\virtualenv_support\pip-8.0.2-py2.py3-none-any.whl\pip\download.py", line 648, in unpack_http_url hashes) File "c:\python27\lib\site-packages\virtualenv_support\pip-8.0.2-py2.py3-none-any.whl\pip\download.py", line 868, in _download_http_url file_path = os.path.join(temp_dir, filename) File "D:\Coding\python\env\lib\ntpath.py", line 85, in join result_path = result_path + p_path UnicodeDecodeError: 'ascii' codec can't decode byte 0xce in position 7: ordinal not in range(128) ---------------------------------------- ...Installing setuptools, pip, wheel...done. Traceback (most recent call last): File "c:\python27\lib\runpy.py", line 162, in _run_module_as_main "__main__", fname, loader, pkg_name) File "c:\python27\lib\runpy.py", line 72, in _run_code exec code in run_globals File "C:\Python27\Scripts\virtualenv.exe\__main__.py", line 9, in <module> File "c:\python27\lib\site-packages\virtualenv.py", line 711, in main symlink=options.symlink) File "c:\python27\lib\site-packages\virtualenv.py", line 944, in create_environment download=download, File "c:\python27\lib\site-packages\virtualenv.py", line 900, in install_wheel call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT) File "c:\python27\lib\site-packages\virtualenv.py", line 795, in call_subprocess % (cmd_desc, proc.returncode)) OSError: Command D:\Coding\python\env\Scripts\python.exe - setuptools pip wheel failed with error code 2 ``` 想不通是什么问题,求解。 补充:如果加上 --no setuptools就可以了 ``` PS D:\Coding\python> virtualenv myenv --no-setuptools New python executable in D:\Coding\python\myenv\Scripts\python.exe Installing pip, wheel...done. ```
©️2020 CSDN 皮肤主题: 成长之路 设计师: Amelia_0503 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值