Mac builds a multi-python development environment

# Mac installation of pyenv and the use of pyenv

When installing virtualwrapper on Mac, the error No module named virtualenvwrapper is reported

The default system of Mac is python2, and I myself use python3 installed by brew

The following is the problem that occurred during my installation

  1. Install virtualwrapper, open a terminal, and enter the following command
pip3 install virtualenv
pip3 install virtualenvwrapper
复制代码
  1. Add code in profile ~/.bash_profile
# Settings for virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh 
复制代码
  1. Make the configuration take effect
source ~/.bash_profile
复制代码

At this time, the following problem occurred:

/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.
复制代码
  1. Cause Analysis

VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is set properly.Judging from the sentence of the error message , it is python2the path pointed to by the environment, so we only need to modify the path to which the environment variable is changed python3.

  1. Solution

    1. Open configuration file
vim ~/.bash_profile
复制代码
2.  在配置文件中添加一行代码
复制代码
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
复制代码
3.  让配置生效, 大功告成
复制代码
source ~/.bash_profile
复制代码

4. Use commands that work in the terminal

1. Create a virtual environment to the configured WORKON_HOME path

 选取默认Python环境创建虚拟环境:
-- mkvirtualenv 虚拟环境名称
 基于某Python环境创建虚拟环境:
-- mkvirtualenv -p python2.7 虚拟环境名称
-- mkvirtualenv -p python3.6 虚拟环境名称
复制代码

2. View the existing virtual environment

-- workon
复制代码

3. Use a virtual environment

-- workon 虚拟环境名称
复制代码

4. Enter | Exit the Python environment of the virtual environment

-- python | exit()
复制代码

5. Install modules for the virtual environment

-- pip或pip3 install 模块名
复制代码

6. Exit the current virtual environment

-- deactivate
复制代码

7. Delete the virtual environment (exit first to delete the current virtual environment)

-- rmvirtualenv 虚拟环境名称
复制代码

Refer to this link for testing and basic instructions (but I failed this installation configuration environment) and then create a test virtualenv directory:

mkdir testvirtual
cd testvirtual
复制代码

You can successfully create a virtual environment env1: virtualenv env1

Next, create a folder to store all virtual environments

mkdir ~/workspaces
cd ~/workspaces
复制代码

Next, create one or more virtual environments env1: mkvirtualenv env1 After success, there will be (env1) in front of the current path 1. List the virtual environment:

$ lsvirtualenv -b
env1
复制代码

2. Switch the virtual environment

workon env1
复制代码

Guess you like

Origin juejin.im/post/7079420028369993741