skip to Main Content

I’m workig in VS code and have cloned an internal repository.This repository comes with some default scripts. I can start a container and open up jupyter notebook from this. If I do that I can easily use functions across the different scripts like if want to get function Z from sql.sql_import import Z. But if I try to do exaclty the same thing but in VS code, it keeps saying "No module named sql.sql_import" and "sql is not a package".
Do you guys know what can be done to solve this?
I’m pretty new to this, but I hope it makes sense.

The code I use in the script where I want to import the function:

from sql.sql_import import Z

A section of the project structure:

AnonymizedEmbeddings
├─ Makefile
├─ README.md
├─ src
│  ├─ main
│  │  ├─ __init__.py
│  │  ├─ import_data.py
│  └─ sql
│     ├─ __init__.py  
│     └─ sql_import.py

I have tried moving around the scripts so they are in the same folder

2

Answers


  1. Add the following code at the top of the import_data.py code:

    import sys
    sys.path.append("./src")
    

    enter image description here

    If you are willing to move the script to the same folder, you can import directly without the above method.

    Login or Signup to reply.
  2. Add following line on top of your code :

    import sys
    sys.path.insert(0, '..')
    

    Check the following source out: https://stackoverflow.com/a/28712742/8464994

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search