virtualenv is a tool to create isolated Python environment.
We can create a virtual environment for a project with virtualenv. So the packages which the project needs doesn't break others. We can also dump the dependent packages for a project in the virtual environment.
virtualenv是一個可以建立Python虛擬環境的工具,我們可以為每個project建立各自的虛擬環境。 讓各個project所需的packaged可以各自獨立,而不影響其他project的開發及測試。當project開發完成後,再把所需的packages從虛擬環境中倒出來。
How to create a virtual environment
[y@Y!MAC:flask_test]$ virtualenv myflask Using base prefix '/Users/xxxxx/anaconda' New python executable in /Users/xxxxx/git/flask_test/myflask/bin/python dyld: Library not loaded: @rpath/libpython3.6m.dylib Referenced from: /Users/xxxxx/git/flask_test/myflask/bin/python Reason: image not found ERROR: The executable /Users/xxxxx/git/flask_test/myflask/bin/python is not functioning ERROR: It thinks sys.prefix is '/Users/xxxxx/git/flask_test' (should be '/Users/xxxxx/git/flask_test/myflask') ERROR: virtualenv is not compatible with this system or executable
Because I've installed Anaconda Python and that virtualenv is not compatible with Anaconda Python. What we need to do is to uninstall it and then install virtualenv with the Anaconda Distribution. You also can follow this to create virtual environments with conda.
[y@Y!MAC:flask_test]$ pip uninstall virtualenv [y@Y!MAC:flask_test]$ conda install virtualenv
You need to delete the failed one env folder, and then create it again.
[y@Y!MAC:flask_test]$ rm -rf myflask/ [y@Y!MAC:flask_test]$ virtualenv myflask Using base prefix '/Users/xxxxx/anaconda' New python executable in /Users/xxxxx/git/flask_test/myflask/bin/python copying /Users/xxxxx/anaconda/bin/python => /Users/xxxxx/git/flask_test/myflask/bin/python copying /Users/xxxxx/anaconda/bin/../lib/libpython3.6m.dylib => /Users/xxxxx/git/flask_test/myflask/lib/libpython3.6m.dylib Installing setuptools, pip, wheel...done. [y@Y!MAC:flask_test]$ ls myflask
After your environment foler created, you need to activate the environment.
[y@Y!MAC:flask_test]$ source myflask/bin/ activate activate.fish easy_install pip pip3.6 python-config python3.6 activate.csh activate_this.py easy_install-3.6 pip3 python python3 wheel [y@Y!MAC:flask_test]$ source myflask/bin/activate (myflask) [y@Y!MAC:flask_test]$
Use deactivate to leave the virtual environment.
(myflask) [y@Y!MAC:flask_test]$ deactivate [y@Y!MAC:flask_test]$