0

I have a project which I'm trying package with conda, install, and run.

I cannot import the module by name, although installed. I can however import the module main.py and execute it's function print_hi. Demonstrated below.

Python 3.10.4 (main, Mar 31 2022, 08:41:55) [GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import myfuncondaproject
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'myfuncondaproject'
>>> import main
>>> main.print_hi("Liam")
Hi, Liam

My project structure.

myfuncondaproject/
├── __init__.py
├── main.py
└── setup.py

Seems to be in line with suggested file structures, although I'm assuming the problem lies in the structure.

Liam Pieri
  • 601
  • 1
  • 6
  • 19

1 Answers1

0

Python looks for imports in the sys.path folders. When you check sys.path on the Python prompt, you'll always find the current folder at the first place.

I guess in your case the current folder is myfuncondaproject and this is why Python can find the main module. To find myfuncondaproject itself you would need to add its parent folder to sys.path

Note the the recommended way of installing own packages is the editable install. With conda this is

conda develop <path to  myfuncondaproject>

How to install my own python module (package) via conda and watch its changes

Peter
  • 10,959
  • 2
  • 30
  • 47
  • I'm looking to install my package from a channel https://anaconda.org/pieri.liam/myfuncondaproject, not install locally. – Liam Pieri Sep 18 '22 at 12:34
  • Good to know. But then why can't you install it, but just the main module? Did you check sys.path? – Peter Sep 18 '22 at 12:40