Mount in Https://www.jianshu.com/p/9f47a9801329Python use Virtualenvwrapper to install virtual environmentsTim_lee Attention 2017.05.04 22:30* words 363 Read 444 comments 0 likes 0
Recommendation: Do not install virtualenv, install Virtualenvwrapper directly
pip install -i https://pypi.douban.com/simple/ virtualenvwrapper
Configured ~/.zshrc
to:
WORKON_HOME=$HOME/virtualenvssource /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenvwrapper.sh
1 Installing the Virtual Environment package
Installation
pip install virtualenvpip install virtualenvwrapper
Watercress Source Installation
sudo pip install -i https://pypi.douban.com/simple virtualenvwrapper
2 configuring Virtualenvwrapper into environment variables
Find a path
sudo find / -name virtualenvwrapper.sh
Or
which virtualenvwrapper.sh
Get
/Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenvwrapper.sh
If this is the case pip3 install
:
/Library/Frameworks/Python.framework/Versions/3.5/bin/virtualenvwrapper.sh
Configuration
Write the virtualenvwrapper into the config file and add two words:
vim ~/.zshrc
or vim ~/.bashrc
:
The virtual environment of the package is placed in $HOME
the user directory under the .virtualenvs
hidden directory, it will create its own.
export WORKON_HOME=$HOME/.virtualenvs
The source is then configured with the Virtualenvs directory, which is found with which.
source /Library/Frameworks/Python.framework/Versions/3.5/bin/virtualenvwrapper.sh
But the configuration file I'm writing here is this complete two lines:
export WORKON_HOME=$HOME/virtualenvssource /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenvwrapper.sh
To create a python2 scrapy directory:
mkvirtualenv py2scrapy
Exit:
deactivate
View Virtual Environments
workon
Entering a virtual environment
workon py2scrapy
Deleting a virtual environment
Enter the directory where the Virtualenvwrapper stores the virtual environment first. This is configured in the .zshrc
file.
cd .virtualenvs
Delete
rm -rf py2scrapy
To create a PYTHON3 virtual environment:
Find Python3 Installation Location first
which python3/Library/Frameworks/Python.framework/Versions/3.5/bin/python3
Create a virtual Environment from Python3 (called py3scrapy).
mkvirtualenv --python=/Library/Frameworks/Python.framework/Versions/3.5/bin/python3 py3scrapy
Or the most straightforward way to let the system find out for itself
mkvirtualenv newpy -p $(which python3)
3 for Virtualenv can not find the error resolution
This error occurs because the Virtualenv base dependency package is installed in the Mac's default Python directory and requires a soft connection ln -s
.
not find virtualenv in your path
The first is find / -name "virtualenv"
to find the location, the last line is virtualenv, you can see in the Frameworks directory, which is where the MAC comes with Python.
"virtualenv"find: /dev/fd/3: Not a directoryfind: /dev/fd/4: Not a directory/Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv
The last soft connection
$ sudo ln -s /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv /usr/local/bin/virtualenv
Python installs the virtual environment using Virtualenvwrapper