PDAL / python

PDAL's Python Support
Other
115 stars 34 forks source link

RunTimeError: weakly_canonical... when importing PDAL in standalone python script. #145

Open nein25 opened 1 year ago

nein25 commented 1 year ago

I've installed PDAL using miniconda via "conda install -c conda-forge pdal python-pdal gdal". I was able to use PDAL in conda prompt successfully. When trying to run a standalone script in either PyCharm or Spyder, I receive the following error message:

E:\dev\tiff_to_las\data>"C:\Users\alex\AppData\Local\miniconda3\envs\pdalpython\python.exe" "E:\dev\tiff_to_las\pdal_tiff_to_las.py" Traceback (most recent call last): File "E:\dev\tiff_to_las\pdal_tiff_to_las.py", line 8, in import pdal File "C:\Users\alex\AppData\Local\miniconda3\envs\pdalpython\Lib\site-packages\pdal__init__.py", line 8, in inject_pdal_drivers() File "C:\Users\alex\AppData\Local\miniconda3\envs\pdalpython\Lib\site-packages\pdal\drivers.py", line 66, in inject_pdal_drivers drivers = libpdalpython.getDrivers() ^^^^^^^^^^^^^^^^^^^^^^^^^^ RuntimeError: weakly_canonical: The device is not ready.: "D:/bld/pdal_1678484181627/_h_env/Library/bin"

E:\dev\tiff_to_las\data>pause Press any key to continue . . .

My machine has a D:/, but it's a DVD RW Drive that is never used. I have tried removing OSGeo4W, which had PDAL. I have tried removing and recreating the PDAL environment in miniconda, and the error persists. Apologies if this is a duplicate, I did a bit of searching to find a similar issue and wasn't able to find any. Thanks a bunch for any help.

hobu commented 1 year ago

I believe "D:/bld/pdal_1678484181627/_h_env/Library/bin" is the path that is used on the @conda-forge builder.

What does conda list show for you?

nein25 commented 1 year ago

Strange... the channel listed beside pdal is pypi, not conda-forge.

image

hobu commented 1 year ago

please try installing from python-pdal and see if you still have issues.

Even so, I do not understand where this error is coming from.

nein25 commented 1 year ago

Could you clarify 'installing from python-pdal' please? Thank you

hobu commented 1 year ago

conda install -c conda-forge python-pdal instead of pip install PDAL. Do this in a fresh environment.

nein25 commented 1 year ago

It still lists pypi as the channel beside PDAL. I did create a new environment for testing. image

image

This may not be pertinent, but it's very likely I downloaded PDAL via PIP a year or more ago before I knew anything about Conda.

hobu commented 1 year ago

It still lists pypi as the channel beside PDAL

confirmed I'm seeing this on a fresh environment too. I do not get the weakly_canonical error when I import pdal however

hobu commented 1 year ago

I think the issue is conda is confused:

I'm not quite sure what to do here. Any ideas @chambbj ?

nein25 commented 1 year ago

I just tried a couple of things, maybe helpful to know - maybe not!

In the Conda prompt, for both my fresh test environment (pdal_test), and the existing one (pdalpython) - I am able to import pdal without issue. When I open Spyder via conda prompt for the pdalpython environment, and import pdal through the console, I get the error message. This is also true with PyCharm and VSCode. Perhaps an issue with my IDE settings?

image

image

image

hobu commented 1 year ago

there have been a number of tickets related to Spyder.

The path that is being checked there must be related to not having a PDAL_DRIVER_PATH environment variable set.

Try setting PDAL_DRIVER_PATH=%CONDA_PREFIX\Library\bin in your Spyder environment and see if the import succeeds.

nein25 commented 1 year ago

That did the trick! I was able to import pdal without issue in Spyder. Thanks so much for the help.

EDIT: I did figure out how to update the path in Spyder preferences.

image

hobu commented 1 year ago

The cause of the issue is PDAL_DRIVER_PATH is set by the Conda Forge recipe when PDAL is configured, and it is embedded as a default lookup directory into the DLL when it is built. In Conda's case, this is the DLL directory relevant to where/how it is being built as a package.

The straight Conda package activate/deactivate scripts take care of handling PDAL_DRIVER_PATH so we never see the error of it trying its default directory that doesn't exist (because it was set to the CONDA_PREFIX of the builder machine that compiled the package, not where it was deployed).

PDAL could certainly not try to list directories that don't exist, and that issue is https://github.com/PDAL/PDAL/issues/4005

This rest of it is an issue that should be handled in the Conda package, but I'm not sure how to do it. https://github.com/conda-forge/python-pdal-feedstock/ is where the conda package is managed.

WillhKessler commented 1 year ago

Any updates on fixing this issue? I'm getting the same 'RuntimeError: weakly_canonical" error in a fresh Anaconda installation, python 3.11.1 and using a fresh environment? I've tried uninstalling and reinstalling everything multiple times without success.

I installed the python-pdal package with command conda install -c conda-forge python-pdal followed by conda update python-pdal