pip - Importing Python package - "ImportError: No module named..." -


i know there lot of questions "importerror: no module named..." ususally seem boil down no __init__.py file or package directory not in $pythonpath. i've checked both of issues , issue not down them.

i have project contains protocol buffer definitions. there's makefile generates source python, java or go. there's setup.py file executes make python. i've run pip install -e . in directory generates source files expected.

i have separate project i'm trying use generated protobufs.

let me illustrate projects:

myproject/ ├── module │   ├── __init__.py │   └── module.py └── main.py  myprotos/ ├── makefile ├── __init__.py ├── my.proto ├── my_pb2.py (generated makefile on install) ├── myprotos.egg-info (generated setup.py) │   ├── pkg-info │   ├── sources.txt │   ├── dependency_links.txt │   └── top_level.txt └── setup.py 

the source of setup.py pretty simple:

import subprocess import sys  setuptools import setup setuptools.command.install import install  class install(install):     """customized setuptools install command - builds protos on install."""     def run(self):         protoc_command = ["make", "python"]         if subprocess.call(protoc_command) != 0:             sys.exit(-1)         install.run(self)   setup(     name='myprotos',     version='0.0.1',     description='',     install_requires=[],     cmdclass={         'install': install,     } ) 

the __init__.py in myprotos contains:

import my_pb2 

and contents of myproject/main.py is:

import sys sys.path.insert(0, '/path/to/myprotos')  import myprotos 

running code, python main.py outputs:

traceback (most recent call last):   file "main.py", line 12, in <module>     import myprotos importerror: no module named myprotos 

what have missed here? seems should work haven't understood crucial.

let have below structure :

demo_proj     |     myproject/     ├── module     │   ├── __init__.py     │   └── module.py     └── main.py      myprotos/     ├── makefile     ├── __init__.py     ├── my.proto     ├── my_pb2.py     ├── myprotos.egg-info     │   ├── pkg-info     │   ├── sources.txt     │   ├── dependency_links.txt     │   └── top_level.txt     └── setup.py 

code in main.py:

import sys sys.path.insert(0, '/path/to/demo_proj')  import myprotos 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -