[Mac] [Python] [Virtualenv] installation configuration and use

Source: Internet
Author: User
Tags virtual environment virtualenv

Installation Help documentation installation VIRTUALENV error as follows

Tekimacbook-air:workspaces hbai$ Source/usr/local/bin/virtualenvwrapper. sh/usr/bin/python:no module named Virtualenvwrappervirtualenvwrapper. SH  forVirtualenvwrapper_python=/usr/bin/PYTHON and thatPATH isset Properly.tekimacbook  which  python/usr/bin/python

After the check found that because the Mac native python2.7 installed under/usr/bin, but installed pycharm will be in the/usr/local/bin will have python3.0 execution files, so the local calls are basically pycharm take over.

Therefore, to py2.7 installation of the corresponding environment, you need to Pycharm to install virtalenv and virtualenvwrapper to

After the installation is complete, you can do it at the command line

    • Create a virtual environment directly $ virtualenv ENV1
    • Create a virtual Environment from mkvirtualenv after importing environment variables
      • $export workon_home=~/Workspaces
      • $source/usr/local/bin/virtualenvwrapper. SH
      • $mkvirtualenv env1

The python environment created in this way is 3.4.

testtekimacbook-air:workspaces test$ virtualenv env1using base prefix'/library/frameworks/python.framework/versions/3.4'New python executableinch/users/test/workspaces/env1/bin/python3.4Also Creating executableinch/users/test/workspaces/env1/bin/pythoninstalling Setuptools, pip, Wheel ... Done.
Testtekimacbook-air:workspaces test$ ls
Env1
Testtekimacbook-air:workspaces test$ RM-RF Env1/testtekimacbook-air:workspaces test$ Export workon_home=~/Workspacestesttekimacbook-air:workspaces test$ Source/usr/local/bin/virtualenvwrapper.SHvirtualenvwrapper.user_scripts Creating/users/test/workspaces/initializevirtualenvwrapper.user_scripts Creating/users/test/workspaces/premkvirtualenvvirtualenvwrapper.user_scripts Creating/users/test/workspaces/postmkvirtualenvvirtualenvwrapper.user_scripts Creating/users/test/workspaces/prermvirtualenvvirtualenvwrapper.user_scripts Creating/users/test/workspaces/postrmvirtualenvvirtualenvwrapper.user_scripts Creating/users/test/workspaces/predeactivatevirtualenvwrapper.user_scripts Creating/users/test/workspaces/postdeactivatevirtualenvwrapper.user_scripts Creating/users/test/workspaces/preactivatevirtualenvwrapper.user_scripts Creating/users/test/workspaces/postactivatevirtualenvwrapper.user_scripts Creating/users/test/workspaces/get_env_detailsvirtualenvwrapper.user_scripts Creating/users/test/workspaces/premkprojectvirtualenvwrapper.user_scripts Creating/users/test/workspaces/Postmkprojecttesttekimacbook-air:workspaces test$lsget_env_details postactivate postmkproject postrmvirtualenv predeactivate Premkvirtuale Nvinitialize postdeactivate postmkvirtualenv preactivate premkproject Prermvirtualenvtestte Kimacbook-air:workspaces test$ mkvirtualenv env1using base prefix'/library/frameworks/python.framework/versions/3.4'New python executableinch/users/test/workspaces/env1/bin/python3.4Also Creating executableinch/users/test/workspaces/env1/bin/pythoninstalling Setuptools, pip, Wheel ... Done. virtualenvwrapper.user_scripts Creating/users/test/workspaces/env1/bin/predeactivatevirtualenvwrapper.user_scripts Creating/users/test/workspaces/env1/bin/postdeactivatevirtualenvwrapper.user_scripts Creating/users/test/workspaces/env1/bin/preactivatevirtualenvwrapper.user_scripts Creating/users/test/workspaces/env1/bin/postactivatevirtualenvwrapper.user_scripts Creating/users/test/workspaces/env1/bin/get_env_details (ENV1) Testtekimacbook-air:workspaces test$ Pythonpython3.4.0(v3.4.0: 04f714765c13, Mar the the, at: Geneva: A) [GCC4.2.1(Apple Inc. Build5666) (dot3)] on Darwintype" Help","Copyright","credits"Or"License" for Moreinformation.>>>

Note: If you need to create a virtual env using your Mac's original py2.7 environment, proceed as follows:

You need to specify the installation of the PIP3 and set the working path of the virtualenvwrapper, but it is not recommended because the operating environment is py2.7

Install virtualenv virtualenvwrapper$ export virtualenvwrapper_python=/usr/local/bin//usr/local/bin/ Virtualenvwrapper. SH

Common commands:

  1. List Virtual environments:

    $ lsvirtualenv -benv1env2
  2. To switch between virtual environments:

    $ workon env1
  3. See which packages are installed in your environment:

    $ lssitepackages
  4. Enter the current environment:

    $ cdvirtualenv
  5. Site-packages into the current environment:

    $ cdsitepackages$ cdsitepackages pip
  6. To replicate a virtual environment:

    $ cpvirtualenv env1 env3Copying env1 as env3...
  7. Exit the virtual Environment:

    $ deactivate
  8. To delete a virtual environment:

    $ rmvirtualenv env2Removing env2...

Reference Document: 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] installation configuration and use

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.