安装帮助文档安装VirtualEnv报错如下

tekiMacBook-Air:workspaces hbai$ source /usr/local/bin/virtualenvwrapper.sh
/usr/bin/python: No module named virtualenvwrapper
virtualenvwrapper.sh: There was a problem running the initialization hooks. If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is
set properly.
tekiMacBook-Air:workspaces hbai$ which python
/usr/bin/python

检查后发现因为Mac本机自带的python2.7 安装在/usr/bin 下面,但是安装了pycharm后会在/usr/local/bin会有python3.0的执行文件,所以本地的调用基本都被pycharm接管了。

因此给py2.7安装相对应的环境时候,需要通过pycharm来进行安装virtalenv 和 virtualenvwrapper才可以

安装完毕后 再在命令行执行即可

  • 直接创建虚拟环境 $ virtualenv env1
  • 导入环境变量以后通过mkvirtualenv 创建虚拟环境
    •   $export WORKON_HOME=~/workspaces
    •   $source /usr/local/bin/virtualenvwrapper.sh
    •   $mkvirtualenv env1

通过这种方式创建的python环境就是3.4的了

testtekiMacBook-Air:workspaces test$ virtualenv env1
Using base prefix '/Library/Frameworks/Python.framework/Versions/3.4'
New python executable in /Users/test/workspaces/env1/bin/python3.
Also creating executable in /Users/test/workspaces/env1/bin/python
Installing setuptools, pip, wheel...done.
testtekiMacBook-Air:workspaces test$ ls
env1
testtekiMacBook-Air:workspaces test$ rm -rf env1/
testtekiMacBook-Air:workspaces test$ export WORKON_HOME=~/workspaces
testtekiMacBook-Air:workspaces test$ source /usr/local/bin/virtualenvwrapper.sh
virtualenvwrapper.user_scripts creating /Users/test/workspaces/initialize
virtualenvwrapper.user_scripts creating /Users/test/workspaces/premkvirtualenv
virtualenvwrapper.user_scripts creating /Users/test/workspaces/postmkvirtualenv
virtualenvwrapper.user_scripts creating /Users/test/workspaces/prermvirtualenv
virtualenvwrapper.user_scripts creating /Users/test/workspaces/postrmvirtualenv
virtualenvwrapper.user_scripts creating /Users/test/workspaces/predeactivate
virtualenvwrapper.user_scripts creating /Users/test/workspaces/postdeactivate
virtualenvwrapper.user_scripts creating /Users/test/workspaces/preactivate
virtualenvwrapper.user_scripts creating /Users/test/workspaces/postactivate
virtualenvwrapper.user_scripts creating /Users/test/workspaces/get_env_details
virtualenvwrapper.user_scripts creating /Users/test/workspaces/premkproject
virtualenvwrapper.user_scripts creating /Users/test/workspaces/postmkproject
testtekiMacBook-Air:workspaces test$ ls
get_env_details postactivate postmkproject postrmvirtualenv predeactivate premkvirtualenv
initialize postdeactivate postmkvirtualenv preactivate premkproject prermvirtualenv
testtekiMacBook-Air:workspaces test$ mkvirtualenv env1
Using base prefix '/Library/Frameworks/Python.framework/Versions/3.4'
New python executable in /Users/test/workspaces/env1/bin/python3.
Also creating executable in /Users/test/workspaces/env1/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /Users/test/workspaces/env1/bin/predeactivate
virtualenvwrapper.user_scripts creating /Users/test/workspaces/env1/bin/postdeactivate
virtualenvwrapper.user_scripts creating /Users/test/workspaces/env1/bin/preactivate
virtualenvwrapper.user_scripts creating /Users/test/workspaces/env1/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/test/workspaces/env1/bin/get_env_details
(env1) testtekiMacBook-Air:workspaces test$ python
Python 3.4. (v3.4.0:04f714765c13, Mar , ::)
[GCC 4.2. (Apple Inc. build ) (dot )] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

注: 如果需要使用mac原先自带的py2.7的环境进行创建virtual env,步骤如下:

需要指定pip3的安装以及设置VIRTUALENVWRAPPER的工作路径,但是不推荐,因为这样运行环境是py2.7的

$ /usr/local/bin/pip3 install virtualenv virtualenvwrapper
$ export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
$ source /usr/local/bin/virtualenvwrapper.sh

常用命令:

  1. 列出虚拟环境:

    $ lsvirtualenv -b
    env1
    env2
  2. 切换虚拟环境:

    $ workon env1
  3. 查看环境里安装了哪些包:

    $ lssitepackages
  4. 进入当前环境:

    $ cdvirtualenv
  5. 进入当前环境的site-packages:

    $ cdsitepackages
    $ cdsitepackages pip
  6. 复制虚拟环境:

    $ cpvirtualenv env1 env3
    Copying env1 as env3...
  7. 退出虚拟环境:

    $ deactivate
  8. 删除虚拟环境:

    $ rmvirtualenv env2
    Removing env2...

参考文档: http://www.jianshu.com/p/51140800e8b4#

http://stackoverflow.com/questions/29486113/problems-with-python-and-virtualenvwrapper-after-updating-no-module-named-virtu

http://stackoverflow.com/questions/27308234/usr-bin-python-vs-opt-local-bin-python2-7-on-os-x

[Mac][Python][Virtualenv]安装配置和使用的更多相关文章

  1. Python virtualenv安装库报错SSL: CERTIFICATE_VERIFY_FAILED

    Python virtualenv安装库报错SSL: CERTIFICATE_VERIFY_FAILED 问题描述 使用pip按照virtualenv报错,如下: pip install virtua ...

  2. Mac上Hive安装配置

    Mac上Hive安装配置 1.安装 下载hive,地址:http://mirror.bit.edu.cn/apache/hive/ 之前我配置了集群,tjt01.tjt02.tjt03,这里hive安 ...

  3. 一网成擒全端涵盖,在不同架构(Intel x86/Apple m1 silicon)不同开发平台(Win10/Win11/Mac/Ubuntu)上安装配置Python3.10开发环境

    原文转载自「刘悦的技术博客」https://v3u.cn/a_id_200 时光荏苒,过隙白驹,即将进入2022年,著名敏捷开发语言Python也放出了3.10最终版,本次我们来展示一下在不同的系统和 ...

  4. [Protobuf] Mac系统下安装配置及简单使用

    Mac下Protobuf安装 Protobuf源码Github地址: https://github.com/google/protobuf 配置环境教程: https://github.com/goo ...

  5. python virtualenv安装说明

    环境说明: virtualenv安装: 第一步,创建目录code: 第二步,创建一个独立的Python运行环境,命名为venv: 新建的Python环境被放到当前目录下的venv目录. 第三步,有了v ...

  6. Mac环境下安装配置Hadoop伪分布式

    伪分布式需要修改5个配置文件(hadoop2.x的配置文件$HADOOP_HOME/etc/hadoop) 第一个:hadoop-env.sh #vim hadoop-env.sh #第25行,由于新 ...

  7. python virtualenv 安装运行saltstack

    需求产生场景:      1.python的virtualenv虚拟环境非常的好用.      2.saltstack作为运维自动化的一个重要组件也挺好用的. 但是:      1.saltsatck ...

  8. Ansible配合Virtualenv安装配置

    Ansible的两种安装模式(Centos7) 1.Yum包管理安装 #yum -y install ansible 2.Git源代码安装[推荐] git clone https://github.c ...

  9. Apache Spark 1.6 Hadoop 2.6 Mac下单机安装配置

    一. 下载资料 1. JDK 1.6 + 2. Scala 2.10.4 3. Hadoop 2.6.4 4. Spark 1.6 二.预先安装 1. 安装JDK 2. 安装Scala 2.10.4 ...

随机推荐

  1. Egret入门学习日记 --- 第十一篇(书中 4.1~4.6节 内容)

    第十一篇(书中 4.1~4.6节 内容) 好了,到了这篇开始,前三章都记录完了. 接下来就是到第四章了. 4.1节 的内容总结一下重点: 1.resource目录下default.res.json文件 ...

  2. Eclipse启动时报错Java was started but returned exit code=13

    Eclipse启动时报错Java was started but returned exit code=13 如图所示 原因是通过第三方更新JRE时,第三方安装的是32位的JRE,与64位的eclip ...

  3. Linux下安装redis 3.0及C语言中客户端实现demo

    1.获取安装文件 wget http://download.redis.io/redis-stable.tar.gz 2.解压文件 tar xzvf redis-stable.tar.gz 3.进入目 ...

  4. 封装ADO库之MFC应用

    Microsoft Activex Data Objects(ADO)支持用于建立基于客户端/服务器和web的应用程序开发的主要功能.其主要优点是易于使用.高速度.低内存支出和占用磁盘空间较少. 本次 ...

  5. zabbix硬件监控以及服务

    大家好今天给大家带来zabbix3.4.8监控主机,那么最近由于我个人的关系.没有及时的更新文章所以,很抱歉那么今天我分享的内容是zabbix3.4.8监控服务器.本章的具体监控服务器如下: 服务器的 ...

  6. StarUML3.1.0版(2019.3.6)生成Java代码

    下载官网 StarUML3.1.0(2019.3.6) 步骤 打开StarUML: 点击菜单栏的Tools: 列表中如果有Java,说明已经有这个生成Java代码的扩展了: 列表里如果没有Java: ...

  7. SAS学习笔记20 CAT函数

  8. Once in a casino CodeForces - 1120B (暴力)

    大意: 给定两个字符串$a,b$, 每个字符为$0-9$, 每次操作将$a$中相邻两位加$1$或减$1$, 操作后每个数仍要为$0-9$, 求最少操作使$a$变成$b$. 先不考虑范围, 判断是否成立 ...

  9. mysql5.7主主(双主)复制

    在server1上操作 vi /etc/my.cnf 修改或添加下面这几行: server-id=1 log-bin=mysql-bin # 启用二进制日志 auto-increment-increm ...

  10. Junit 学习笔记

    目录 Junit 学习笔记 1. 编写测试用例时需要注意 2. 出现结果分析 3. Junit 运行流程 4. Junit 常用注解 5. Junit 测试套件的使用 6. Junit 参数化设置 J ...