Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The name shadowing issue for the package 'neural_renderer' #17

Closed
mengyuest opened this issue Aug 30, 2018 · 2 comments
Closed

The name shadowing issue for the package 'neural_renderer' #17

mengyuest opened this issue Aug 30, 2018 · 2 comments

Comments

@mengyuest
Copy link

mengyuest commented Aug 30, 2018

Hi, I tried the code and could not execute python3 ./examples/example1.py successfully. It raised the error

Traceback (most recent call last):
  File "examples/example1.py", line 12, in <module>
    import neural_renderer as nr
  File "/foo/bar/neural_renderer/neural_renderer/__init__.py", line 3, in <module>
    from .load_obj import load_obj
  File "/foo/bar/neural_renderer/neural_renderer/load_obj.py", line 8, in <module>
    import neural_renderer.cuda.load_textures as load_textures_cuda
ImportError: No module named 'neural_renderer.cuda.load_textures'

It seems like to be a "name shadowing" problem as the local package name conflicts with the installed packages. After altering the inner (second) "neural_renderer" filename to others, it worked as expected. Could it be better to rename the local dirname or just mention that in the README.md? I am not sure whether this is a common issue. I am using python3. Thanks.

PS: Referenced from The name shadowing trap

A simple case for showing "name shadowing" is (assuming you have numpy)

  1. mkdir numpy
  2. touch numpy/__init__.py
  3. python3 -c "import numpy.random" and you will get "No module named..." error
@mengyuest mengyuest changed the title The name shadowing for the package 'neural_renderer' The name shadowing issue for the package 'neural_renderer' Aug 30, 2018
@nkolot
Copy link
Collaborator

nkolot commented Aug 30, 2018

Yes I am aware that this can happen if you try to run the examples from the root folder of the repo. The local directory is named neural_renderer because this is the standard practice when distributing python packages (you need to supply a setup.py and place your package named foo under the foo/ directory). One problem here is that neural_renderer.cuda.load_textures is an external module written in C++ and CUDA and not a Python module, and is compiled when you run setup.py So when you try to import anything that starts with neural renderer and you are in the root folder it may shadow a globally installed package.

Check for example this package:

@DavisDDD
Copy link

I had the same problem, I'm using pycharm. The problem is beacause the import package can't be in the same path with the demo.py. My solution is copy the /neural_renderer to another path, then add it as an external lib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants