mac安装python虚拟环境

编程入门 行业动态 更新时间:2024-10-27 02:27:32

mac安装python虚拟<a href=https://www.elefans.com/category/jswz/34/1771403.html style=环境"/>

mac安装python虚拟环境

前言:继续安装中,这节记录 mac 安装 python 虚拟环境,多版本共存...

1. 安装 pip -- python的包管理工具:

sudo easy_install pip

安装成功,出现下面:

2. 安装完pip之后,就要安装 virtualenv:

sudo pip install virtualenv # 卸载安装:sudo pip uninstall virtualenv

据说如果是用的macOS 10.11可能会出现以下的提示(我用的是macOS 10.13,也出现以下的提示):

1 The directory '/Users/xxxx/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

2 The directory '/Users/xxxx/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

可以忽略,或者执行下面的命令(其实它已经在提示的最后建议要加上 -H):

sudo -H pip install virtualenv

3. 然后要安装virtualenvwrapper:

Virtaulenvwrapper 是 virtualenv 的扩展包,可以更方便地新增,删除,复制,切换虚拟环境。

sudo -H pip install virtualenvwrapper

安装成功如下:

据说,有人在安装的时候,遇到了这样的错误(我未遇到,未验证):

1 Installing collected packages: six2 Found existing installation: six 1.4.1

3 DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version. This isdue to the fact that uninstalling a distutils project will only partially uninstall the project.4 Uninstalling six-1.4.1:5 Exception:6 Traceback (most recent call last):7 File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/basecommand.py", line 215, inmain8 status =self.run(options, args)9 File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/commands/install.py", line 317, inrun10 prefix=options.prefix_path,11 File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_set.py", line 736, ininstall12 requirement.uninstall(auto_confirm=True)13 File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_install.py", line 742, inuninstall14 paths_to_remove.remove(auto_confirm)15 File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_uninstall.py", line 115, inremove16 renames(path, new_path)17 File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/utils/__init__.py", line 267, inrenames18 shutil.move(old, new)19 File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, inmove20 copy2(src, real_dst)21 File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, incopy222 copystat(src, dst)23 File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, incopystat24 os.chflags(dst, st.st_flags)25 OSError: [Errno 1] Operation not permitted: '/tmp/pip-vyEme3-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'

执行下面的命令,重新安装:

1 sudo pip install pbr2 sudo pip install --no-deps stevedore3 sudo pip install --no-deps virtualenvwrapper

4. 创建虚拟环境:

source /usr/local/bin/virtualenvwrapper.sh

5. 让文件生效,并且要将命令写到 ~.bash_profile 里。

创建虚拟环境,指定python的版本,并将虚拟环境命名为python3

mkvirtualenv --python=/usr/local/bin/python3 python3

6. 创建好虚拟环境之后,会自动进入虚拟环境

退出虚拟环境的命令为 deactivate

虚拟环境的一些命令:

workon   会列出所有的虚拟环境

workon  [name]  会进入指定的虚拟环境

deactivate   退出当前的虚拟环境

mkvirtualenv  [name] 创建虚拟环境

rmvirtualenv  [name] 删除虚拟环境

更多推荐

mac安装python虚拟环境

本文发布于:2023-06-28 20:00:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/932807.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:环境   mac   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!