virtualenv won't activate on windows

后端 未结 18 1624
走了就别回头了
走了就别回头了 2020-12-07 14:05

Essentially I cannot seem to activate my virtualenv environment which I create.

I\'m doing this inside of windows powershell through using

scripts\\a         


        
相关标签:
18条回答
  • 2020-12-07 14:20

    On Windows, open Windows PowerShell as Administrator

    Set-ExecutionPolicy Unrestricted -Force
    

    create virtual environment

    pip install virtualenv
    virtualenv foo
    cd .\foo
    .\Scripts\activate
    

    0 讨论(0)
  • 2020-12-07 14:20

    in windows you should activate the virtual environment by following command in cmd

    E:\your_environment\Scripts>activate.bat

    if the environment is activated then it show your environment name enclosed with bracket like this

    (your_environment) E:\your_environment\Scripts>

    Also we can ensure by checking with where.exe it will list our active python environment with order of hierarchy

     (your_environment) E:\your_environment\Scripts>where.exe python
    
     E:\your_environment\Scripts\python.exe
    
     C:\Python27\python.exe
    

    if you need to deactivate then do

    (your_environment) E:\your_environment\Scripts>deactivate.bat

    0 讨论(0)
  • 2020-12-07 14:26

    Another quick solution I have found here (it is applicable for Windows Powershell only) is like this:

    First run

    Scripts\cmd
    

    Then run

    Scripts\activate.bat
    

    At this position, your Virtualenv is activated. Now if you deactivate it and want to activate it again later in the same session of powershell, you just need to run-

    Scripts\activate
    

    There is no need to cmd or activate.bat command later.

    0 讨论(0)
  • 2020-12-07 14:26

    For me on Windows 10 x64 - Open cmd as an Administrator - powershell - type Set-ExecutionPolicy Unrestricted -Force

    Voila, reOpen VSCode and start pythoninnngg

    0 讨论(0)
  • 2020-12-07 14:29

    Follow these steps to the latter. step 1. Use Windows PowerShell as ADMINISTRATOR. (VERY IMPORTANT) and cd into the project folder. Run

    virtual env
    

    step 2. Check in the scripts folder if you have your activate.bat file

    \env\Scripts\activate.bat #It has to be there.
    

    step 3. If it is not here make sure you have an internet connection and run this again

    virtual env 
    

    step 4. If the activate.bat file is there in the script folder proceed. step 5. run this on your shell

    Set-ExecutionPolicy Unrestricted -Force
    

    step 6. To activate virtualenv on Windows, activate script is in the Scripts folder :

    env\Scripts\activate.bat
    

    step 7 check for the (env) at the start of each line this shows you are on the virtual environment

    step 8. To reactivate when yo come back to the project the second time run:

    .\\env\Scripts\activate
    
    0 讨论(0)
  • 2020-12-07 14:31

    Moving comment to answers section :)

    According to Microsoft Tech Support it might be a problem with Execution Policy Settings. To fix it, You should try executing Set-ExecutionPolicy Unrestricted -Scope Process (as mentioned in the comment section by @wtsiamruk) in Your Power Shell. This would allow running virtualenv in the current Power Shell session.

    Unsafe way, but recommended by MS Tech Support would be Set-ExecutionPolicy Unrestricted -Force (which do unleash powers to screw Your system up).

    EDIT: edited and added the SAFER way from the comment section.

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