简体   繁体   中英

Python2.7 has an error for “module not found” on my custom libs. Although path is correct and directory is python package

I am using pyChram to run my python. Although I have a correct path on Pycharm interpreter, my own module is showing the error "No module found".

This question may have answered few times and obvious but I am not able to find the correct answer. Please see the attached pic that has my pyCharm setup. I have main directory "python " as root.

My pycharm setup

python
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 12:04:33) 
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.path)
['', '/anaconda3/lib/python36.zip', '/anaconda3/lib/python3.6', '/anaconda3/lib/python3.6/lib-dynload', '/anaconda3/lib/python3.6/site-packages', '/anaconda3/lib/python3.6/site-packages/aeosa']

Error:

{code}
"$ python Test_run/Game_tic_tac_toe.py 
Traceback (most recent call last):
  File "Test_run/Game_tic_tac_toe.py", line 4, in <module>
    from functions.Tic_Tac_Toe import *
ImportError: No module named functions.Tic_Tac_Toe"[enter image description here][1]
{code}

Tree;: The directory "python" is the root. MacBook-HS-Pro:PycharmProjects$ tree

.
└── Python
    ├── Test_run
    │   ├── Game_tic_tac_toe.py
    │   └── __init__.py
    ├── config
    │   ├── Bk_card_value.py
    │   └── __init__.py
    └── functions
        ├── Tic_Tac_Toe.py
        └── __init__.py

From what I can see in what you posted, you are attempting to use the python script in Python/Test_Run/Game_tic_tac_toe.py to load the module located at Python/functions. You do not have your project directory in your sys.path, so your import, from functions.Tic_Tac_Toe import * , cannot find the functions module.

You would either want to use a relative import for your module or fix your python path.

It looks like you have attempted to alter your python path in your Game_tic_tac_toe.py script. The problem as I see it is that you used what appears to be a Windows path to specify a directory on MacOSX. If you are using Windows, make sure you have the correct path. If you are using MacOSX, remove the c: from your path and see if that works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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