bash: mkvirtualenv: command not found

后端 未结 11 1428
天命终不由人
天命终不由人 2020-12-02 06:15

After following the instructions on Doug Hellman\'s virtualenvwrapper post, I still could not fire up a test environment.

[mpenning@tsunami ~]$ mkvirtualenv          


        
相关标签:
11条回答
  • 2020-12-02 06:37

    Prerequisites to execute this command -

    1. pip (recursive acronym of Pip Installs Packages) is a package management system used to install and manage software packages written in Python. Many packages can be found in the Python Package Index (PyPI).

      sudo apt-get install python-pip

    2. Install Virtual Environment. Used to create virtual environment, to install packages and dependencies of multiple projects isolated from each other.

      sudo pip install virtualenv

    3. Install virtual environment wrapper About virtual env wrapper

      sudo pip install virtualenvwrapper

    After Installing prerequisites you need to bring virtual environment wrapper into action to create virtual environment. Following are the steps -

    1. set virtual environment directory in path variable- export WORKON_HOME=(directory you need to save envs)

    2. source /usr/local/bin/virtualenvwrapper.sh -p $WORKON_HOME

    As mentioned by @Mike, source `which virtualenvwrapper.sh` or which virtualenvwrapper.sh can used to locate virtualenvwrapper.sh file.

    It's best to put above two lines in ~/.bashrc to avoid executing the above commands every time you open new shell. That's all you need to create environment using mkvirtualenv

    Points to keep in mind -

    • Under Ubuntu, you may need install virtualenv and virtualenvwrapper as root. Simply prefix the command above with sudo.
    • Depending on the process used to install virtualenv, the path to virtualenvwrapper.sh may vary. Find the appropriate path by running $ find /usr -name virtualenvwrapper.sh. Adjust the line in your .bash_profile or .bashrc script accordingly.
    0 讨论(0)
  • 2020-12-02 06:38

    Using Git Bash on Windows 10 and Python36 for Windows I found the virtualenvwrapper.sh in a slightly different place and running this resolved the issue

    source virtualenvwrapper.sh 
    /c/users/[myUserName]/AppData/Local/Programs/Python36/Scripts
    
    0 讨论(0)
  • 2020-12-02 06:46

    On Windows 10, to create the virtual environment, I replace "pip mkvirtualenv myproject" by "mkvirtualenv myproject" and that works well.

    0 讨论(0)
  • 2020-12-02 06:48

    Try:

    source `which virtualenvwrapper.sh`
    

    The backticks are command substitution - they take whatever the program prints out and put it in the expression. In this case "which" checks the $PATH to find virtualenvwrapper.sh and outputs the path to it. The script is then read by the shell via 'source'.

    If you want this to happen every time you restart your shell, it's probably better to grab the output from the "which" command first, and then put the "source" line in your shell, something like this:

    echo "source /path/to/virtualenvwrapper.sh" >> ~/.profile

    ^ This may differ slightly based on your shell. Also, be careful not to use the a single > as this will truncate your ~/.profile :-o

    0 讨论(0)
  • 2020-12-02 06:50

    Use this procedure to create virtual env in ubuntu

    step 1

    Install pip

       sudo apt-get install python-pip
    

    step 2

    Install virtualenv

       sudo pip install virtualenv
    

    step 3

    Create a dir to store your virtualenvs (I use ~/.virtualenvs)

       mkdir ~/.virtualenvs
    

    or use this command to install specific version of python in env

    virtualenv -p /usr/bin/python3.6 venv
    

    step 4

       sudo pip install virtualenvwrapper
    

    step 5

       sudo nano ~/.bashrc
    

    step 6

    Add this two line code at the end of the bashrc file

      export WORKON_HOME=~/.virtualenvs
      source /usr/local/bin/virtualenvwrapper.sh
    

    step 7

    Open new terminal (recommended)

    step 8

    Create a new virtualenv

      mkvirtualenv myawesomeproject
    

    step 9

    To load or switch between virtualenvs, use the workon command:

      workon myawesomeproject
    

    step 10

    To exit your new virtualenv, use

     deactivate
    

    and make sure using pip vs pip3

    OR follow the steps below to install virtual environment using python3

    Install env

    python3 -m venv my-project-env
    

    and activate your virtual environment using the following command:

    source my-project-env/bin/activate
    
    0 讨论(0)
  • 2020-12-02 06:51

    Solution 1:

    For some reason, virtualenvwrapper.sh installed in /usr/bin/virtualenvwrapper.sh, instead of under /usr/local/bin.

    The following in my .bash_profile works...

    source "/usr/bin/virtualenvwrapper.sh"
    export WORKON_HOME="/opt/virtual_env/"
    

    My install seems to work fine without sourcing virtualenvwrapper_bashrc

    Solution 2:

    Alternatively as mentioned below, you could leverage the chance that virtualenvwrapper.sh is already in your shell's PATH and just issue a source `which virtualenvwrapper.sh`

    0 讨论(0)
提交回复
热议问题