导入错误? (PYTHON 3.2) [英] Import error? (PYTHON 3.2)

查看:171
本文介绍了导入错误? (PYTHON 3.2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我自己的模块名为v_systems,我试图将该模块导入另一个python文件(也保存在与保存文件v_systems相同的目录中)
我需要将其导入为 import v_systems as vs 或即使我尝试导入为 import v_systems



但是它给我一个错误,说没有模块v_systems存在。



我可以如何解决这个错误?

解决方案

它可能不在系统路径中。执行以下操作:



它需要位于 sys.path 的目录中。我做的是我创建了一个文件夹(不重要的地方)称为模块,其中我拥有我在其中下载/创建的所有模块。说我把它放在 C:\Users\USER\Modules 中。您可以将此模块也放在那里。



您需要将路径复制到文件夹。



然后,进入控制面板。单击系统,然后在左侧面板上有一个名为高级系统设置的选项。点击那个。从弹出窗口的底部,单击环境变量。看看你是否创建了一个名为 PYTHONPATH 的变量。很可能,你不会。所以,通过按NEW创建一个变量(在第二部分)。将它命名为 PYTHONPATH ,对于Variable值,放入文件路径。 (对于我的例子,文件路径是 C:\Users\USER\Modules )。希望这有助于:)



我在控制面板中插入了系统(属性)位置后如何到达的截图:


I have my own module named v_systems, and I'm trying to import that module in another python file (which is also saved in the same directory as the file v_systems is saved) I need to import it as import v_systems as vs or even if I try to import as import v_systems.

However it gives me an error saying no module v_systems exists.

How may I fix this error?

解决方案

It might not be in the system path. Do the following:

It needs to be in the directory of the sys.path. What I did is I created a folder (doesn't really matter where) called "Modules" in which I have all of my modules that I download/create in there. Say I put it in C:\Users\USER\Modules. You can put this module in there as well.

You need to copy the path to the folder.

Then, go to Control Panel. Click System, then on the left panel there is an option called "Advanced System Settings". Click that. From the bottom of the window that pops up, click "Environment Variables". Look to see if you have a variable created called PYTHONPATH. Most likely, you don't. So, create a variable (in the second section) by pressing "NEW". Name it PYTHONPATH and for the Variable value, put in the file path. (For my example, the file path is C:\Users\USER\Modules). Hope this helps :)

I inserted a screenshot of how to get there once you get to the System (Properties) location in Control Panel:

这篇关于导入错误? (PYTHON 3.2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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