Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 已安装lxml,但无法在Windows上工作_Python_Windows_Pip_Lxml - Fatal编程技术网

Python 已安装lxml,但无法在Windows上工作

Python 已安装lxml,但无法在Windows上工作,python,windows,pip,lxml,Python,Windows,Pip,Lxml,我需要根据XSD验证XML文件。为了实现这一点,我想使用。问题是,即使我已经从lxml导入etree安装了,并且已经将lxml安装到C:\Python33\Lib\site packages\lxml\,我还是得到了错误 Traceback (most recent call last): File "C:\Users\asmithe\Documents\dev1\TestParse.py", line 3, in <module> from lxml import et

我需要根据XSD验证XML文件。为了实现这一点,我想使用。问题是,即使我已经从lxml导入etree安装了
,并且已经将lxml安装到
C:\Python33\Lib\site packages\lxml\
,我还是得到了错误

Traceback (most recent call last):
  File "C:\Users\asmithe\Documents\dev1\TestParse.py", line 3, in <module>
    from lxml import etree as ET_l
ImportError: No module named lxml
在cmd中,我是这样做的

C:\Users\dev1\Documents\test>python
Python 3.3.5 (v3.3.5:62cf4e77f785, Mar  9 2014, 10:35:05) [MSC v.1600 64 bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from lxml import etree
>>>
>>> def main():
...     print('hi')
...
>>>
>>> if __name__ == "__main__":
...     main()
...
hi
>>> exit()
但是如果我试着运行它

> ImportLxml.py
然后我得到

C:\Users\dev1\Documents\test>ImportLxml.py
Traceback (most recent call last):
  File "C:\Users\dev1\Documents\XML test\TestImport.py", line 1, in <module>

    from lxml import etree
ImportError: No module named lxml
将配置为默认使用3.3.5:

py -3
或者——假设您在上次安装Python时选择安装Python启动器——:


如果在安装Python 3.3时决定不安装Python Launcher for Windows,请参阅以了解手动步骤:

将正确的文件组与.py脚本关联:

assoc .py=Python.File
assoc .py=Python.File
将所有Python文件重定向到新的可执行文件:

ftype Python.File=C:\Path\to\pythonw.exe "%1" %*
ftype Python.File=C:\Path\to\py.exe "%1" %*

这可用于将
Python.File
的类型配置为您选择的Python解释器,即3.3.5的类型。(作为一种良好实践,
Python.File
应该指向
py.exe
Python.exe
;上面的
pythonw.exe
示例直接引用了文档,但这是一种不好的实践)


或者,如果磁盘上有一个
py.exe
(与Python 3.3一起安装),但它没有被使用,则可以稍微修改这些指令:

将正确的文件组与.py脚本关联:

assoc .py=Python.File
assoc .py=Python.File
将所有Python文件重定向到新的可执行文件:

ftype Python.File=C:\Path\to\pythonw.exe "%1" %*
ftype Python.File=C:\Path\to\py.exe "%1" %*

…同样,调整路径以适合安装Python 3.3.x的位置。

您的系统中是否有多个Python安装?@AnandSKumar是Python 2.7和3.3(我打算使用3.3)。你是在问我是否有多个lxml安装?在文件夹
C:\Python33\Lib\site packages
中有子文件夹
lxml
lxml-3.4.4.dist-info
。您可以执行-
导入系统吗;sys.version
在python终端内部,您将在该终端中获得库导入错误。@AnandSKumar显示为3.3.5。但是当我从命令行python导入lxml时,它就工作了?还可以添加scrpt吗?“将Python Launcher for Windows配置为默认使用3.3.5:“我不知道该怎么做。我添加了
#!蟒蛇3和蟒蛇!C:\python33\python.exe
,我尝试了以下操作,但默认情况下我无法让它使用python 3解释器。不要按照这些说明操作——按照安装程序中特定于python的说明操作。我链接它们是有原因的。当然,你也可以使用
ftype
将Python文件与
py.exe
关联起来!python3
不起作用意味着您当前的关联是到(2.x)
python.exe
而不是
py.exe
。您还可以重新运行3.3.5安装程序,并确保选中了启动器作为选项。
Python.File
应运行Python.exe(或py.exe),而不是pythonw.exe(或pyw.exe)。后者通常与.pyw脚本和
Python.noconfig
文件类型相关联。