Python在执行pip和virtualenv时挂起,未产生任何结果 [英] Python hangs while executing pip and virtualenv and brings no results

查看:97
本文介绍了Python在执行pip和virtualenv时挂起,未产生任何结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过执行virtualenv myenv为我的项目设置虚拟环境.该文件夹似乎已生成,但是命令挂起了,我无法执行其他命令.我不得不关闭控制台并重新启动cmd.如我所说,该文件夹已生成,但是我无法通过venv\Scripts\activate激活虚拟环境.

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.

我在尝试执行pip freeze > requirements.txt时遇到了相同的行为.尽管我在项目中使用了很多软件包,但已生成了文件,但它是空的.当我只执行pip freeze时,将打印软件包列表,但是命令再次挂起,因此我不得不再次关闭控制台.

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.

我多次尝试了这两个过程,但均未成功.我在Windows cmd和Anaconda Prompt(Anaconda版本:Anaconda3 2.4.1; Python:3.5.1)中进行了尝试.

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.

推荐答案

一个简单的解决方案(起作用有效)是使用Powershell作为管理员,而不是cmd

A simple solution to this (which does work) would be to use Powershell as an Administrator, instead of cmd.

相反,请使用cmd作为管理员,尽管我建议为所有目的使用功能更强大的Powershell

Conversely, use cmd as an administrator, though I would recommend using the much-more powerful Powershell for any and all purposes!

为什么有效:

Why this works:

许多命令需要超级用户权限(在Linux中,请考虑root/sudo),以便正确执行.

A lot of commands need super-user rights (think root/ sudo in linux) in order to be properly executed.

由于Windows中还没有sudo之类的东西,因此您可以通过管理员权限来实现它.

Since there is no such thing as as sudo in Windows yet, you can implement it via admin privileges.

干杯!

这篇关于Python在执行pip和virtualenv时挂起,未产生任何结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆