问题
I tried to set up a virtual environment for my project by executing virtualenv myenv. The folder seemed to be generated, but the command hung, and I couldn't execute another command. I had to close the console and restart cmd. The folder was generated, as I said, but I couldn't activate the virtual environment by venv\Scripts\activate.
I met the same behaviour while trying to execute pip freeze > requirements.txt. The file was generated, but it was empty, although I used a lot of packages in my project. When I executed just pip freeze, the list of packages was printed, but the command hung again, and I had to close the console again.
I tried both procedures many times, but with no success. I tried that in Windows cmd and Anaconda Prompt (Anaconda version: Anaconda3 2.4.1; Python: 3.5.1).
EDIT: when I tried to do this for the very first time some days ago, I succeeded in activating the virtual environment, but only for one time.
回答1:
A simple solution to this (which does work) would be to use Powershell as an Administrator, instead of cmd.
Conversely, use cmd as an administrator, though I would recommend using the much-more powerful Powershell for any and all purposes!
Why this works:
A lot of commands need super-user rights (think root/ sudo in linux) in order to be properly executed.
Since there is no such thing as as sudo in Windows yet, you can implement it via admin privileges.
Cheers!
来源:https://stackoverflow.com/questions/44687986/python-hangs-while-executing-pip-and-virtualenv-and-brings-no-results