为什么在Windows Vista命令提示符下运行'import pylons'时找不到Pylons?

3 投票
1 回答
1060 浏览
提问于 2025-04-16 04:47

当我尝试在虚拟的Python环境中导入pylons时,出现了这个错误:

C:\env\Scripts>python
Python 2.7 (r27:82525, Jul  4 2010, 07:43:08) [MSC v.1500 64 bit (A
MD64)] on win32
Type "help", "copyright", "credits" or "license" for more informati
on.
>>> import pylons
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\env\lib\site-packages\pylons-1.0-py2.7.egg\pylons\__init
__.py", line 6, in <module>
    from paste.registry import StackedObjectProxy
ImportError: No module named registry

根据我的理解,这个错误是Python在告诉我,它找不到一个叫registry的模块。可能这是我在安装Pylons时遇到的错误导致的,具体情况可以在这里查看 为什么在Windows Vista 64上用easy_install安装Pylons 1.0时最后一行会出错?

看起来很多Pylons的组件都安装好了,但我猜registry没有安装,或者Pylons就是无法找到它。

有没有什么办法可以解决这个问题?

1 个回答

1

在你能使用pylons之前,必须先激活虚拟环境。

C:\Users\Josh>env\scripts\activate
(env) C:\Users\Josh>python
ActivePython 2.6.2.2 (ActiveState Software Inc.) based on
Python 2.6.2 (r262:71600, Apr 21 2009, 15:05:37) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pylons
>>>

和这个相比

C:\Users\Josh\env\Scripts>python
ActivePython 2.6.2.2 (ActiveState Software Inc.) based on
Python 2.6.2 (r262:71600, Apr 21 2009, 15:05:37) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> pylons
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'pylons' is not defined
>>>

我猜想你在虚拟环境外和里面都安装了pylons这个包。所以Python允许你导入pylons,但paste这个包没有在虚拟环境外安装,所以你才会遇到错误。

运行activate这个批处理脚本(应该在你的env\Scripts文件夹里)应该能解决这个问题。

撰写回答