Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: No module named 'src' #7

Open
kikiki1121 opened this issue Dec 13, 2018 · 15 comments
Open

ModuleNotFoundError: No module named 'src' #7

kikiki1121 opened this issue Dec 13, 2018 · 15 comments

Comments

@kikiki1121
Copy link

I want to do network learning.
・Create data / Training_images
・Place my data set in Training_images
・Run  python src / train.py -a seranet_v1 -g 0
I attempted learning by the above procedure.
However, I got an error.
ModuleNotFoundError: No module named 'src'
I studied variously and tried changing it myself, but I could not solve it

@corochann
Copy link
Owner

I way is to execute script from this project root
OK:
SeRanet$ python src/inference.py input.jpg
NG:
src$ python inference.py input.jpg

@corochann
Copy link
Owner

Second way is to set PYTHONPATH

$ export PYTHONPATH=path-to-seranet-directory:$PYTHONPATH

please modify path-to-seranet-directory properly according to your environment.

@kikiki1121
Copy link
Author

Is it the same for train.py?
Also, export command is not recognized and pythonpath can not be changed

@corochann
Copy link
Owner

Yes, it is same for train.py.
Can you copy and paste from the line where you execute the code, until get the end of error message?

SeRanet$ python src/train.py

@kikiki1121
Copy link
Author

D:\SeRanet-master>python src/train.py -a seranet_v1 -g 0
prepare model
Traceback (most recent call last):
File "src/train.py", line 71, in
import arch.seranet_v1 as model_arch
File "D:\omichi\SeRanet-master\src\arch\seranet_v1.py", line 9, in
import src.functions as CF
ModuleNotFoundError: No module named 'src'

I get the above error.

@corochann
Copy link
Owner

I see you are using windows.
How about this?

D:\SeRanet-master> set PYTHONPATH=D:\SeRanet-master
D:\SeRanet-master> python src/train.py

@kikiki1121
Copy link
Author

() D:\SeRanet-master>set PYTHONPATH=D:\SeRanet-master

() D:\SeRanet-master>python src/train.py -a seranet_v1 -g 0
prepare model
Traceback (most recent call last):
File "src/train.py", line 71, in
import arch.seranet_v1 as model_arch
File "D:\SeRanet-master\src\arch\seranet_v1.py", line 9, in
import src.functions as CF
ModuleNotFoundError: No module named 'src'

I get the above error.

@corochann
Copy link
Owner

Well,,, in that case how about adding the following code in top of train.py? (please modify and try execute it).

import sys
import os
sys.path.append(os.pardir)
sys.path.append(os.path.join(os.pardir, os.pardir))

@kikiki1121
Copy link
Author

I changed train.py.
However, the same error came out.

@corochann
Copy link
Owner

oh i see... that's wired.
what kind of environment you are trying? In default windows command line?

@kikiki1121
Copy link
Author

Running using anaconda command line is used.

@corochann
Copy link
Owner

I only tried with normal windows command line.

Anyway, the problem should be in PYTHONPATH setting. So If you are using anaconda command line, could you refer this to set correct configuration?
https://stackoverflow.com/questions/43099096/setting-pythonpath-on-windows-under-anaconda-without-elevated-privileges/43402606

@Gajender0707
Copy link

I am facing the same issue but I don't know how to fix it... my error is

PS C:\Users\asdf\Documents\D.S\END-TO-END-PROJECTS\Test> & C:/python/python.exe c:/Users/asdf/Documents/D.S/END-TO-END-PROJECTS/Test/src/exception2.py
Traceback (most recent call last):
File "c:\Users\asdf\Documents\D.S\END-TO-END-PROJECTS\Test\src\exception2.py", line 2, in
from src.logger import logging
ModuleNotFoundError: No module named 'src'
PS C:\Users\asdf\Documents\D.S\END-TO-END-PROJECTS\Test>

I have a folder named test in which src and in src there is logger and exception but i'm not able to import logger from src

@ghost
Copy link

ghost commented May 26, 2024

I am facing the same issue but I don't know how to fix it... my error is

PS C:\Users\asdf\Documents\D.S\END-TO-END-PROJECTS\Test> & C:/python/python.exe c:/Users/asdf/Documents/D.S/END-TO-END-PROJECTS/Test/src/exception2.py Traceback (most recent call last): File "c:\Users\asdf\Documents\D.S\END-TO-END-PROJECTS\Test\src\exception2.py", line 2, in from src.logger import logging ModuleNotFoundError: No module named 'src' PS C:\Users\asdf\Documents\D.S\END-TO-END-PROJECTS\Test>

I have a folder named test in which src and in src there is logger and exception but i'm not able to import logger from src

Did u solve this error?? I need help

@Gajender0707
Copy link

Gajender0707 commented May 30, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants