Can not activate a virtualenv in GIT bash mingw32 for Windows

后端 未结 5 1323
慢半拍i
慢半拍i 2020-11-29 21:41

When I try to activate my virtualenv from GIT bash mingw32 I do not get the expected response.

NOTE: py is the folder for Python projects in my Google

相关标签:
5条回答
  • 2020-11-29 22:08

    Doing Scripts/activate runs the script in a new instance of the shell, which is destroyed after the script execution. To run the script in your current shell, use either . Scripts/activate or source Scripts/activate.

    Scripts/activate.bat does not work here because it is written in Batch, Windows cmd.exe language, and not Bash.

    0 讨论(0)
  • 2020-11-29 22:08

    I know there's an answer already on here but I thought I could post my solution for those coming to this post a lot later like me. After installing python 3.8.2 and making sure you selected add python to c drive path on the initial install, do the following...

    1. Install virtualenv with pip install virtualenv and then test.

    2. Go into your project folder, type pip freeze this will show all the installed packages which may not be wanted for a new project.

    3. Type python -m venv ./venv and then cd venv,

    4. Type . Scripts/activate. You should now see (venv), which is the name you gave in step 3.

    5. cd .. back to the root of your project folder and type pip freeze to check this virtual environment if clear for a new project.

    (venv) user@DESKTOP MINGW64 ~/Documents/yourproject

    0 讨论(0)
  • 2020-11-29 22:11

    On Windows10, you could go in the directory of your virtualenv where the Scripts folder is placed then enter the below command

    source ./Scripts/activate
    

    Note the .(dot) without this it was giving error to me when I use it like above mentioned then the solution provided by Pierre worked for me.

    0 讨论(0)
  • 2020-11-29 22:13

    How to activate then deactivate a venv with Git Bash


    To access your python in Windows 10, you need to add the .exe when creating the virtual environment.

    $ python.exe -m venv Scripts
    

    Then you can move into the Scripts folder you created for the virtual environment.

    $ cd Scripts/
    

    Now you have to call on it to activate the virtual environment.

    $ source ./Scripts/activate
    

    When you are done you just deactivate the virtual environment.

    $ deactivate
    

    Screenshot how to activate/deactivate Git Bash venv


    0 讨论(0)
  • 2020-11-29 22:18

    Just do . Scripts/activate in your virtual environment folder

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