#πŸ”’ Poetry users, please help a noob understand how to import my code

28 messages Β· Page 1 of 1 (latest)

wild swan
#

I've created a poetry project with "poetry new my_project", great now I have the file structure shown below. I've created a core.py file inside src/my_project and create a function called "hello_world". My question is: lets I want to make a quick check to see if the function is working properly, so I want to create a sandbox.py file, import my_package and call the function. What is the professional way of doing so? where would you guys create that sandbox.py file? I've been trying different ways of doing it but I keep getting "no module found" errors. I've tried creating it in the tests/ folder, same error also

└── my_first_project
β”œβ”€β”€ README.md
β”œβ”€β”€ pyproject.toml
β”œβ”€β”€ sandbox.py
β”œβ”€β”€ src
β”‚Β Β  └── my_first_project
β”‚Β Β  β”œβ”€β”€ init.py
β”‚Β Β  └── core.py
└── tests
└── init.py

steep raftBOT
#

@wild swan

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

indigo juniper
wild swan
#

so, I've created a hello_test.py inside the tests/ directory. What code would you write to import the hello function that is inside src/my_first_project/core.py?

indigo juniper
wild swan
#

Hope you don't mind me sharing a printscreen of what my situation is

#

As you can see on test_hello, it's not finding the my_first_project module, probably because it is inside of src

wild swan
#

btw, thanks in advance for the help πŸ™‚

indigo juniper
#

i'm able to use poetry new temp-poetry-proj, create a hello.py file with a hello function, and then do from temp_poetry_project.hello import hello anywhere in the project with no extra configuration

wild swan
wild swan
indigo juniper
#

try running poetry install in your terminal?

wild swan
#

I did, still showing the error

#

how do you run your hello.py file? I use vscode

#

I'm asking this because maybe you are using a different command to run the file, like "poetry run" or something, idk

indigo juniper
#

well you should have a central starting point, like __main__.py and your python -m project-name will execute that

#

i think poetry also has scripts you can define and run

#

its been a while since i used poetry since i switched away

wild swan
#

What are you using now?

indigo juniper
wild swan
#

thank you so much for the help

steep raftBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.