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

Cannot import from custom module in different directory #245

Open
dewball345 opened this issue May 11, 2021 · 5 comments
Open

Cannot import from custom module in different directory #245

dewball345 opened this issue May 11, 2021 · 5 comments

Comments

@dewball345
Copy link

Hello There,

This is my directory structure:

module1
---__init__.pyj
---test.pyj
file1
---__init__.pyj
---main.pyj

in test.pyj

def hello():
   print("Hello")

and in my main.pyj

from module1.test import hello

However, when I compile my python, I get this error message:

[ImportError: Failed Import: 'module1' module doesn't exist in any of the import directories: ., C:\Users\*username*\rapydscript_ryact\RapydScript\src\lib] {
  filename: ←[32m'main.pyj'←[39m,
  readfile_error: ←[90mundefined←[39m
}

Why is this happening? And how can i fix it?

@valq7711
Copy link
Collaborator

What does your compilation command look like?

@valq7711
Copy link
Collaborator

from the doc:

RapydScript first tries to search the current directory of the file for the import. If that fails, it tries to search user-defined imports (which can be set via RAPYDSCRIPT_PATH environment variable as colon-separated directories, or semi-colon separated on Windows), and finally in the RapydScript builtin directory. This search order allows the user to easily override inbuilt functions.

You have two ways:

  • define RAPYDSCRIPT_PATH
  • create a simple one-line file with import file1.main in the parent folder of your packages and pass it to the compiler

@dewball345
Copy link
Author

ok, i'm kind of confused on the RAPYDSCRIPT_PATH one; Are you supposed to change the environment variable whenever you create a new package, or are editing in a new project? That would be a nightmare! Also, I tried the second method but it didn't work

@dewball345
Copy link
Author

dewball345 commented May 12, 2021

ok, i solved it by configuring the --import-path attribute, though I don't understand the RAPYDSCRIPT_PATH variable

@Aareon
Copy link

Aareon commented May 30, 2021

For example, if you wanted to import from a directory using --import-path, you would do something like:
rapydscript main.py --import-path "./lib"

Using environment variables is a little different.
export RAPYDSCRIPT_PATH="./lib"; rapydscript main.py
If you wanted to save this environment variable permanently, add it to your .profile. Your profile will depend on your OS.

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