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

No module named 'pyngp' #43

Closed
zxzxde opened this issue Jan 18, 2022 · 15 comments
Closed

No module named 'pyngp' #43

zxzxde opened this issue Jan 18, 2022 · 15 comments

Comments

@zxzxde
Copy link

zxzxde commented Jan 18, 2022

Missing In run.py

@bit704
Copy link

bit704 commented Jan 18, 2022

I have the same problem.

@Tom94
Copy link
Collaborator

Tom94 commented Jan 18, 2022

Please check your CMake/build logs for whether Python was detected and pyngp actually built.

If CMake can't detect your Python installation, it will only build the testbed binary. Further, if pyngp was built in different folder than instant-ngp/build, run.py will be unable to detect it and you have to supply the correct path to the import statement.

@mmalex
Copy link
Contributor

mmalex commented Jan 18, 2022

to expand on this a little in case it helps you understand the root cause (tho the advice Tom94 gives is the right thing to actually take action on) - the python binding relies on there being a file with a filename something like pyngp.cp39-win_amd64.pyd in your path (but see below). this (on windows) may also depend on some dlls such as cublas64_11.dll and `cublasLt64_11.dll' (some of the numbers in those filenames will depend on your python and cuda versions, so they are just for illustration).

so - all these files (the pyd and the cublas dlls) must be in your path. but... how do they get there?
if everything has built as expected, all of those files should actually be found in your instant-ngp/build folder. (if they are not there, you have a build issue). then, what happens is that the scripts/run.py (by way of some code early in scripts/common.py) explicitly adds the build/ folder to your path, in order that python can find these files. voila!

the error you are seeing is basically that python cannot find these files in your path, and the code in common.py is failing to add a useful directory somehow. perhaps the files are not there, or not in the build/ folder, or perhaps you are running a different version of python than the one that was built against.

I have seen a windows setup where running 'python' ran (say) 3.9, but cmake had built instant-ngp against (say) 3.7 or 3.8. it may be worth checking what version of python you are running run.py through, vs what verision is in the filename of the .pyd file.

@MiZhenxing
Copy link

Hi, the built python lib is in your build directory.
For me it is named as pyngp.cpython-37m-x86_64-linux-gnu.so, which means it is compiled by python 3.7.
As mmalex said, just add following codes in run.py:

pyngp_path = '/path/to/your/build'
sys.path.append(pyngp_path)
import pyngp as ngp

Replace the pyngp_path with your actually build path.
Please make sure that the python version used for running codes matches the version of .so file.

@Tom94 Tom94 closed this as completed Feb 3, 2022
@624memorials
Copy link

My file name is called pyngp.cp310-win_amd64 which made me believe it's for python 3.10. But when updating to python 3.10 all kinds of other modules break and I think it would be easier to build a 3.9 version of pyngp. But I have no clue how to do that.

@samanturner
Copy link

@624memorials I had exactly the same issue. I resolved it by doing the following.

First, I followed MiZhenxing's advice by adding the following code to the 'run.py' file:

pyngp_path = '\build'
sys.path.append(pyngp_path)
import pyngp as ngp  # this line should already be there near the top of the code

I then installed python version 3.10 into the virtual environment

conda install python=3.10

This will ask you for confirmation that it will automatically update or downgrade various packages. This should hopefully work for you. Happy coding!

@entropical
Copy link

I had this problem and realised it was because I installed Python after I had already run the make.

Now python is there, I will redo the make, and I suspect it will work.

@willehlad
Copy link

i've been fighting with this problem all bloody day ;p .. i finally figure it out.. i just renamed pyngp.cp39-win_amd64.pyd (or whatever yours is called) to pyngp.pyd and it worked

@nemtiax
Copy link

nemtiax commented Oct 3, 2022

I also had this issue, documenting what worked for me here in case it helps others.

I'm on Windows, and had run the cmake commands in a Developer powershell, but was running my python in an Anaconda shell inside an Anaconda environment. This meant that the python that cmake saw and the python that the scripts saw was different, and so it couldn't find pyngp.

To fix this, I first set up the Developer powershell to use conda. In the shell, I went to my conda install directory (C:\Users<usnerame>\anaconda3\condabin) and ran conda init. Next, I launched a Developer powershell AS ADMINISTRATOR, and ran Set-ExecutionPolicy RemoteSigned, which is required to let conda run its set up scripts when launching a new shell. Then, I launched a fresh shell, and was able to use conda activate ngp to enter my conda environment (which I had named "ngp").

Next, I removed my old build folder. I had previously tried just running cmake again, but that didn't fix it. I needed to remove build, and re-run cmake from scratch within the conda environment. After doing this, all my pythons were in agreement, and I could import pyngp without issue.

@lukexyz
Copy link

lukexyz commented Nov 2, 2022

To add to the post above – I simply opened a new Developer powershell and rebuilt the library (cmake), but with the correct conda env activated (and pyexr already pip installed).

@coronet1127
Copy link

command to execute
py -3.9 scripts/run.py --scene data/nerf/fox/transforms.json

@alanhzh
Copy link

alanhzh commented Jan 30, 2023

To add to the post above – I simply opened a new Developer powershell and rebuilt the library (cmake), but with the correct conda env activated (and pyexr already pip installed).

I followed this instruction, but I got this: "ImportError: DLL load failed while importing pyngp: the given module is not found."

@halamesp
Copy link

Change the python version (here from 3. 7 in the download ) in the cmakelist file to the your environment python version (3.10 in my PC). then cmake and build again. Then it works

if (NGP_BUILD_WITH_PYTHON_BINDINGS)
find_package(Python 3.10 COMPONENTS Interpreter Development)
if (Python_FOUND)
add_subdirectory("dependencies/pybind11")
endif()
endif()

@frederiknolte
Copy link

frederiknolte commented Apr 18, 2024

If someone else is wondering how to install Instant-NGP with a specific Python version (other than the currently activated version), it can be done by adding the following flags to the build command:

cmake . -B build \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DPython_EXECUTABLE:FILEPATH=/path_to_python/bin/python3 \
-DPython_LIBRARIES:FILEPATH=/path_to_python/lib/libpython3.10.so \
-DPython_INCLUDE_DIR:PATH=/path_to_python/include/python3.10

@jsusgin-aist
Copy link

Personnally, I struggled with this error for a day and I could run scripts/run.py changing "/path/to/python" in build/CMakeCache.txt by my current path to python. I work with conda and it seems to work now.

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