的Python3。ImportError:没有名为“ myfile”的模块

标记
iMac-Mark:~ Mark$ python3
Python 3.3.2 (v3.3.2:d047928ae3f6, May 13 2013, 13:52:24) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import myfile
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'myfile'

我是Python和一般编程的新手。我读了一些有关的文章sys.path__PATH__但我什么都不懂。

Itdxer

解决方案:

  1. __init__.py附近档案myfile.py吗?
  2. 你有目录sys.path吗?(如果不像这样添加它sys.path.append('path / to / python / code'))
  3. 如果您尝试从python环境导入它,则需要在该文件附近运行python shell

您也可以尝试运行此代码

import sys
print(sys.path)

在输出中,您可以看到python看到的所有目录的列表。如果您的文件位于其他目录中,则必须更改目录或pythonsys.path

你可以这样

$ python3
>>> import sys
>>> sys.path.append('/all/path/to/Desktop/Python')
>>> import myfile

或者像这样

$ cd ~/Desktop/Python
$ python3
>>> import myfile

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

ImportError:没有名为sklearn的模块(Python)

python3:ImportError:没有名为xxxx的模块

Python 3 ImportError:没有名为“ ConfigParser”的模块

Python 3:ImportError“没有名为Setuptools的模块”

ImportError:没有名为“ html.parser”的模块;'html'不是软件包(python3)

Python泡菜:ImportError:没有名为__main__的模块

Python ImportError:没有名为os的模块

ImportError:没有名为boto3的模块

ImportError:Python 3中没有名为“模型”的模块

ImportError:Python 3.6中没有名为comtypes的模块

Python:ImportError:没有名为_pluggy的模块

Python3 ImportError:没有名为“ _tkinter”的模块

ImportError:Linux上没有名为“ cplex” Python的模块

Python ImportError:没有名为sty的模块

ImportError:没有名为pymc3的模块

ImportError。没有名为Commons错误的模块-python

ImportError:没有名为解析python / node js的模块

/ bin / python3:没有名为pip的模块

python ImportError:没有名为包的模块

ImportError:在Python 3.4中没有名为“ PIL”的模块

ImportError:没有名为“ requests”的模块Python 3.4.0

ImportError:没有名为jabber:python的模块

Python ImportError:没有名为zhelpers的模块

python3-ImportError:没有名为“ _chipset”的模块

GAE Python PyML ImportError:没有名为_ckernel的模块

Python:ImportError:没有名为请求的模块

Python:ImportError 没有名为 mysql.connector 的模块

Python:ImportError:没有名为 Selenium Windows 的模块

python3中没有名为json的模块