简体   繁体   中英

ModuleNotFoundError: No module named with virtualenv and need understanding how to structure it for production

I am trying to understand how python packages/modules work in virtualenv and how I can structure it for distribution .. I have getting this error: ModuleNotFoundError: No module named lib . I have a very simple project

Project/lib
   - __init__.py
   - calc.py
Project/tests
   - __init__.py
   - test_calc.py

I need to be able to access calc.py from the tests and it gives me this error when I import. I understand I should add the Project dir into the sys.path (I have also read the python docs). If I were to distribute this project what do I need to do to make sure the paths are added and the packages are ready to be consumed ? do I need a Makefile or setup.py . There is so many things I am seeing and its a bit confusing. What is the best approach for production?

You are correct in saying that you should add the directory to the sys.path variable. Now, all you need to do is, depending on how your code is set up, import the main folder (lib), or import the calc file from lib

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM