简体   繁体   English

如何导入与sys modul同名的本地模块?

[英]How to import local module with same name as sys modul?

I've compiled pyzmq (python zeromq binding) module and want to use that one instead system one. 我已经编译了pyzmq(python zeromq绑定)模块,并希望使用那个而不是系统一个。

How to skip module loading from system so that my import zmq first searches in current folder? 如何从系统跳过模块加载,以便我的导入zmq首先在当前文件夹中搜索?

By installing it in a location that is listed earlier in sys.path . 通过将其安装在sys.path先前列出的位置。

The directory your project is in, for example, is always listed first in sys.path and other packages in the same directory will be found before system locations. 例如,项目所在的目录始终首先列在sys.path并且系统位置之前将找到同一目录中的其他包。 In other words, put pyzmq in the same folder as your script and it'll Just Work. 换句话说,将pyzmq放在与脚本相同的文件夹中,它就是Just Work。

You can also add entries to sys.path by listing them in the PYTHONPATH environment variable; 您还可以通过在PYTHONPATH环境变量中列出条目来向sys.path添加条目; these will be inserted into sys.path before system locations. 这些将在系统位置之前插入sys.path

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM