Python virtualenv非常慢 [英] Python virtualenv is very slow

查看:312
本文介绍了Python virtualenv非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ubuntu 12.04 x64与Python 2.7.3,我刚刚将一个Django 1.5.4站点移植到virtualenv 1.7.1.2。



然而,我注意到,当从活动的virtualenv运行时,Python命令比在使用系统的Python安装时慢得多。例如。 runnig python manage.py验证与系统的Python持续〜1秒,而在virtualenv环境中运行的相同命令持续约4秒。这是正常吗?我错过了什么吗?注意:当本地Django开发服务器正在运行时,我没有注意到在使用该站点时出现了效率问题,而是使用Apache + virtualenv来部署此站点时,会遇到效率问题吗?



< 。似乎只影响从virtualenv中的shell运行的python命令...这是真的吗?



Update1:​​



这里有一个我实际获得的时间的例子:

  enric @ developer :〜/ Documentos / workspace / EurekaStart $ time python manage.py validate 
找到错误

real 0m1.049s
用户0m0.648s
sys 0m0.120s
enric @ developer:〜/ Documentos / workspace / EurekaStart $ source env / bin / activate
(env)enric @ developer:〜/ Documentos / workspace / EurekaStart $ time python manage.py validate
0发现错误

real 0m5.261s
用户0m0.968s
sys 0m1.032s

更新2:



我已经进一步测试并更新了virtualenv到最新版本1.10 .1我注意到时代已经有所改善,但只是一个小时(0.5和1秒之间)。我也试图用 - system-site-packages 标志创建env,时间要好得多,但比使用系统默认的Python还要慢。以下是时间:



使用 env 创建而不使用 system-site-packages

 (env)enric @ developer:〜/ Documentos / workspace / EurekaStart $ time python manage。 py验证
0发现错误

真实0m4.648s
用户0m1.008s
sys 0m0.824s

使用 env2 使用 system-site-packages

 (env2)enric @ developer:〜/ Documentos / workspace / EurekaStart $ time python manage.py validate 
0发现错误

real 0m1.921s
用户0m0.760s
sys 0m0.312s

只是要注意,没有任何env的正常执行持续1秒(如update1中所述)。






我刚刚创建了与新鲜的Ubuntu 12.04(live CD)一样安装的完全相同的libs的virtualenv,一切都按预期工作!这个新机器甚至运行得更快:在我的机器上是0.6s而不是1.0。



一个有趣的注意事项:如果我使用从新鲜的Ubuntu创建的virtualenv我的真正的机器运行速度与执行命令没有virtualenv一样快,这是实际预期的。但是,如果我使用从这台机器创建的virtualenvs,那么它们的运行速度很慢。



所以,我猜想系统中安装的lib真的会影响一个virtualenv被创建。



现在,问题是... 有没有办法清除我的Ubuntu安装,以便能够创建高效的virtualenvs ?有没有任何已知的lib可能导致这个问题? (系统中没有破坏的包,因为我已经检查过)。

解决方案

我认为效率与virtualenv有关的问题可能是由其分配的HDD分区的类型引起的。在我的情况下,从NTFS分区运行virtualenv会导致它非常慢。但是,使用与Ext4分区完全相同的libs的virtualenv可以正常工作。


I'm working on Ubuntu 12.04 x64 with Python 2.7.3 and I've just ported a Django 1.5.4 site to virtualenv 1.7.1.2.

However, I've noticed that Python commands are much slower when they are run from an active virtualenv than when using the system's Python installation. E.g. runnig python manage.py validate with system's Python lasts ~1s while the same command run inside a virtualenv environment lasts ~4s. Is this normal? Am I missing something? Will I have efficiency issues when deploying this site with Apache + virtualenv?

Note: When the local Django development server is running I haven't noticed efficiency issues while using the site. It seems to only affect python commands run from shell inside a virtualenv... Is this true?

Update1:

Here you have an example of the times I'm actually getting:

enric@developer:~/Documentos/workspace/EurekaStart$ time python manage.py validate
0 errors found

real    0m1.049s
user    0m0.648s
sys     0m0.120s
enric@developer:~/Documentos/workspace/EurekaStart$ source env/bin/activate
(env)enric@developer:~/Documentos/workspace/EurekaStart$ time python manage.py validate
0 errors found

real    0m5.261s
user    0m0.968s
sys     0m1.032s

Update 2:

I've done further testing and updated virtualenv to the latest version 1.10.1 and I've noticed that the times times have improved, but just a litte (between 0.5s and 1s). I have also tried to create the env with the --system-site-packages flag and time is much better, but still slower than using system's default Python. Here are the times:

Using env created without using system-site-packages:

(env)enric@developer:~/Documentos/workspace/EurekaStart$ time python manage.py validate
0 errors found

real    0m4.648s
user    0m1.008s
sys     0m0.824s

Using env2 created using system-site-packages:

(env2)enric@developer:~/Documentos/workspace/EurekaStart$ time python manage.py validate
0 errors found

real    0m1.921s
user    0m0.760s
sys     0m0.312s

Just to note, normal execution without ANY env lasts 1s (as stated in update1).


I've just created the same virtualenv with exactly the same libs installed inside from a fresh Ubuntu 12.04 (live CD) and everything works as expected! It even ran faster on this new machine: 0.6s instead of 1.0 in my machine.

One interesting point to note: If I use the virtualenv created from the fresh Ubuntu in my real machine it runs as fast as executing the command without virtualenv, which is what is actually expected. But, if I use the virtualenvs created from this machine, then they run very slow.

So, I guess that the libs installed in the system really influence on how a virtualenv is created.

Now, the question would be... Is there any way to purge my Ubuntu installation to be able to create efficient virtualenvs? Is there any known lib that may cause this issue? (There aren't broken packages in the system, as I've already checked this).

解决方案

I think that the efficiency issues with virtualenv may be caused by the type of HDD partition it is allocated. In my case, running virtualenv from a NTFS partition causes it to be really slow. However, running a virtualenv with exactly the same libs from an Ext4 partition works as expected.

这篇关于Python virtualenv非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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