Jump to content
Brent

Error 'No module named' on importing python-file

Recommended Posts

I am making a project using Python4Delphi. 

For this, I need a number of classes in Python. I have put these classes in a separate Python file ('CustomClasses.py').

When I try to import the python-file, I get the following error message: ‘ModuleNotFoundError: No module named 'CustomClasses’.'

I don't know why I get this error, because when I import any library I downloaded with pip, I do not get this error.

The files are in the same folder, so that can't be the issue.

I could put everything in one file, but this would make it so confusing that I would prefer not to do so.

Can anyone help me solve this?

Share this post


Link to post

I am confused.  You are talking about your own python file (CustomClasses), but also something you installed via pip.

 

For python to find your file it needs to be either on the python path or on the current directory.

 

Run the following using P4D:

import sys
import os
print(sys.path)
print(os.getcwd())
print(sys.executable)

and check the values of the path and the current directory.  Also check which python version you are using.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×