问题描述
对我来说,它位于C:\ Python33 \ libs.
For me, it's located at C:\Python33\libs.
作为参考-这与C:\ Python33 \ Lib 不是文件夹相同-请注意大写字母和缺少's'.
For reference - this is not the same folder as C:\Python33\Lib - note the capitalization and lack of an 's'.
在我正在使用的一台计算机上,我只是将.py文件放到libs文件夹中,并且可以像库/模块一样导入和使用它(对不起,我不太了解术语),无论在哪里我正在从事的项目是
On one computer I was working on, I simply dropped a .py file into the libs folder and could import and use it like a library / module (sorry, I don't really know terminology very well), regardless of where the project I was working on is.
但是,在尝试将其复制到另一台计算机上时,此操作不起作用.尝试导入只会给出没有名为X的模块"错误.
However, in trying to duplicate this on another machine, this doesn't work. Attempting to import simply gives a "no module named X" error.
因此,显然我误解了libs文件夹的用途以及它与Lib文件夹的区别.
So, clearly I'm misunderstanding the purpose of the libs folder, and how it differs from the Lib folder.
那么,到底是什么?
推荐答案
如果将libs/与lib/进行比较,您会注意到后者包含* .py文件,而前者包含* .lib文件.使用文本编辑器进行的进一步研究将显示* .py文件是人类可读的(我希望是),而* .lib文件不是.
If you compare libs/ vs. Lib/ you'll notice that the latter is full of *.py files and the former has *.lib files. Further investigation with a text editor will show that *.py files are human-readable (I hope) and the *.lib files are not.
这就是真正的区别.如果您想了解更多,.lib文件是静态链接库,用于构建.dll,C扩展名和所有这些好东西.头朝兔子 孔(如果您对此感兴趣).
And that's really the difference. If you want to know more, the .lib files are static-link libraries, used for building .dlls, C extensions, and all that good stuff. Head on down the rabbit hole if that interests you.
您所要解决的问题:您是否应该能够在其中放置模块并能够导入它们?并不真地.这是该文件夹包含在您的路径中的副作用.从模块文档:
On to the meat of your question: are you supposed to be able to drop modules in there and be able to import them? Not really. That is a side effect of that folder being included in your path. From the Modules docs:
- 包含输入脚本的目录(或当前目录).
- PYTHONPATH(目录名称列表,其语法与shell变量PATH相同).
- 与安装有关的默认设置.
- the directory containing the input script (or the current directory).
- PYTHONPATH (a list of directory names, with the same syntax as the shell variable PATH).
- the installation-dependent default.
各种安装方法都会修改%PATH%或%PYTHONPATH%,因此我无法告诉您确切的位置;在我的Windows框上,python安装程序为我修改了%PATH%,因此您可能应该先看看那里.值得注意的是,我的路径不包括Python33/libs/,所以我不希望它默认存在.
Various installation methods will modify %PATH% or %PYTHONPATH% so I can't tell you exactly where to look; on my windows box, the python installer modified %PATH% for me, so you should probably look there first. Notably, my path does not include Python33/libs/ so I would not expect it to be there by default.
这篇关于Python-libs子文件夹有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!