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

WindowsError when importing openslide using 64-bit version #23

Closed
macmatt22 opened this issue May 15, 2017 · 20 comments
Closed

WindowsError when importing openslide using 64-bit version #23

macmatt22 opened this issue May 15, 2017 · 20 comments
Labels

Comments

@macmatt22
Copy link

Context

Issue type (bug report perhaps?):
Operating system (Windows 10):
Platform (64-bit):
OpenSlide version (2016-7-17 64 bit release):
Slide format (NA):

Details

Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "C:\dev_res\python\python2_713\lib\site-packages\openslide\__init__.py", line 29, in <module>
        from openslide import lowlevel
    File "C:\dev_res\python\python2_713\lib\site-packages\openslide\lowlevel.py", line 41, in <module>
        _lib = cdll.LoadLibrary('libopenslide-0.dll')
    File "C:\dev_res\python\python2_713\lib\ctypes\__init__.py", line 440, in LoadLibrary
        return self._dlltype(name)
    File "C:\dev_res\python\python2_713\lib\ctypes\__init__.py", line 362, in __init__
        self._handle = _dlopen(self._name, mode)
WindowsError: [Error 127] The specified procedure could not be found'

I installed the OpenSlide binaries and added the bin folder to my system path. I then installed python-openslide using pip. I tried same workflow with Python 3.5.3 and encountered the same problem. Interestingly, when I tested this with the 32-bit version of Python(2.7)/OpenSlide I did not have this issue. However, I have a 64-bit machine and would prefer to use the 64-bit versions.

Not sure if this is a bug or is specific to my configuration. Any help would be greatly appreciated!

@bgilbert
Copy link
Member

Hi @macmatt22, we've received a user report that this error is caused by another copy of one of OpenSlide's dependencies, such as zlib1.dll, in the search path.

@macmatt22
Copy link
Author

Thanks for your help! Yeah, it turns out that for at least zlib1.dll there were multiple copies installed by other applications. As the user report stated, I was able to fix the problem by starting python inside the openslide/bin directory - this changes the search hierarchy such that the openslide version of zlib1.dll is found first. For the benefit of a future reader, I added the following to lowlevel.py to allow it to work outside of openslide/bin:

os.environ['PATH'] = "path-to-openslide-bin" + ";" + os.environ['PATH']

Of course with replacing path-to-openslide-bin with the appropriate path and importing os module. This puts the directory of the dll's at the front of the search path.

@jxu
Copy link

jxu commented Jul 5, 2019

The issue is that the file is named zlib1.dll instead of something more specific like zlib1-2-11.dll

PS C:\Users\jxu\Downloads\openslide-win64-20171122\openslide-win64-20171122\bin> (Get-Item .\zlib1.dll).versionInfo

ProductVersion   FileVersion      FileName
--------------   -----------      --------
1.2.11           1.2.11           C:\Users\jxu\Downloads\openslide-win64-20171122\opensl...

And OpenSlide finds the wrong DLL

>>> from ctypes.util import find_library
>>> find_library("zlib1")
'C:\\Program Files\\Intel\\WiFi\\bin\\zlib1.dll'

@NourEddy
Copy link

I tried to add os.environ['PATH'] = "path-to-openslide-bin" + ";" + os.environ['PATH'], it works perfectly when I use python with Consol, but when I spyder i get the same error as befor can someone help me?

@LiesMH
Copy link

LiesMH commented Apr 16, 2020

I have a similar error. I installed openslide-python with pip and added the path to environment variables, but when I try to import openslide, this error occurs:

FileNotFoundError: Could not find module 'libopenslide-0.dll' (or one of its dependencies). Try using the full path with constructor syntax.

I have tried to add os.environ['PATH'] = "path-to-openslide-bin" + ";" + os.environ['PATH'] to lowlevel.py and to start Python from the openslide bin, but that doesn't help. I also uninstalled openslide several times and tried with different downloads.

Any ideas?

@mallyagirish
Copy link

@LiesMH
Maybe you've figured it out already, but I have been facing the same issue and simply adding that line to lowlevel.py didn't work for me either. But I finally got it working after seeing this comment. That is, after ensuring I had the path to the openslide bin folder added to PATH, I only needed to change the line in lowlevel.py that loads the 'libopenslide-0.dll' to the following.

_lib = cdll.LoadLibrary(ctypes.util.find_library("libopenslide-0.dll"))

@jalilahmed
Copy link

jalilahmed commented Oct 7, 2020

OS: Windows 10
Python: Anaconda, Python 3.8.5
I think the problem is with the library 'zlib1.dll'. I tried to run find_library(libopenslide-0) and it located the library perfectly fine. But even with addition of os['PATH'] = path-to-openslide-bin" + ";" + os.environ['PATH'] the location for the zlib1.dll is Intel\WiFI\bin.
I solved the issue by adding, the following lines to the lowlevel.py file in , site-packages/openslide/
import os
os.add_dll_directory('PATH_TO_MY_OPENSLIDE_BINARY')

@narminGhaffari
Copy link

I am facing the same problem while trying to import openslide package.
my question is, the openslide folder inside the site-packages, I dont have any "bin" folder, Can some one help me with this issue?

@jalilahmed
Copy link

@narminGhaffari You are looking at the wrong location. If you go through the installation guide of openslide-python on https://pypi.org/project/openslide-python/ . You first have to Install Openslide. For windows, that means extracting the binaries provided at https://openslide.org/download/. In that folder you will find the /bin/ folder which you have to provide in the PATH variable in environment variables. I hope it solves your issue.

@narminGhaffari
Copy link

@jalilahmed thank you alot for the respond. I downloaded the openslide and added this line to the enviroment path and also as every body recomended I added this line os.environ['PATH'] = r"C:\openslide-win64-20171122\openslide-win64-20171122\bin" + ";" + os.environ['PATH'] to the lowlevel.py file.

but unfortunatly I am still receieving the winError 126. I sthere any thing else which I have to do?

@cardenm
Copy link

cardenm commented May 24, 2021

OS: Windows 10
Python: Anaconda, Python 3.8.5
I think the problem is with the library 'zlib1.dll'. I tried to run find_library(libopenslide-0) and it located the library perfectly fine. But even with addition of os['PATH'] = path-to-openslide-bin" + ";" + os.environ['PATH'] the location for the zlib1.dll is Intel\WiFI\bin.
I solved the issue by adding, the following lines to the lowlevel.py file in , site-packages/openslide/
import os
os.add_dll_directory('PATH_TO_MY_OPENSLIDE_BINARY')

Thank you, this worked perfectly!

@huangjin520
Copy link

I tried to add os.environ['PATH'] = "path-to-openslide-bin" + ";" + os.environ['PATH'], it works perfectly when I use python with Consol, but when I spyder i get the same error as befor can someone help me?

i meet the same error , are you find the solution?

@narminGhaffari
Copy link

I tried to add os.environ['PATH'] = "path-to-openslide-bin" + ";" + os.environ['PATH'], it works perfectly when I use python with Consol, but when I spyder i get the same error as befor can someone help me?

i meet the same error , are you find the solution?

This is how I solved the issue Finally :

`
from ctypes.util import find_library

if platform.system() == 'Windows':
os.environ['PATH'] = r"C:\openslide-win64-20171122\openslide-win64-20171122\bin" + ";" + os.environ['PATH']
_lib = cdll.LoadLibrary(find_library("libopenslide-0.dll"))
`

@huangjin520
Copy link

I tried to add os.environ['PATH'] = "path-to-openslide-bin" + ";" + os.environ['PATH'], it works perfectly when I use python with Consol, but when I spyder i get the same error as befor can someone help me?

i meet the same error , are you find the solution?

This is how I solved the issue Finally :

`
from ctypes.util import find_library

if platform.system() == 'Windows':
os.environ['PATH'] = r"C:\openslide-win64-20171122\openslide-win64-20171122\bin" + ";" + os.environ['PATH']
_lib = cdll.LoadLibrary(find_library("libopenslide-0.dll"))
`

Thanks for your answer ! After i modify the lowlevel.py as your solution ,but my spyder still can't import openslide because of OSError: [WinError 127] . I think maybe there is something wrong in my system that i can't find.

@narminGhaffari
Copy link

I tried to add os.environ['PATH'] = "path-to-openslide-bin" + ";" + os.environ['PATH'], it works perfectly when I use python with Consol, but when I spyder i get the same error as befor can someone help me?

i meet the same error , are you find the solution?

This is how I solved the issue Finally :
from ctypes.util import find_library if platform.system() == 'Windows': os.environ['PATH'] = r"C:\openslide-win64-20171122\openslide-win64-20171122\bin" + ";" + os.environ['PATH'] _lib = cdll.LoadLibrary(find_library("libopenslide-0.dll"))

Thanks for your answer ! After i modify the lowlevel.py as your solution ,but my spyder still can't import openslide because of OSError: [WinError 127] . I think maybe there is something wrong in my system that i can't find.

Did you download the openslide bin to your system?

@huangjin520
Copy link

I tried to add os.environ['PATH'] = "path-to-openslide-bin" + ";" + os.environ['PATH'], it works perfectly when I use python with Consol, but when I spyder i get the same error as befor can someone help me?

i meet the same error , are you find the solution?

This is how I solved the issue Finally :
from ctypes.util import find_library if platform.system() == 'Windows': os.environ['PATH'] = r"C:\openslide-win64-20171122\openslide-win64-20171122\bin" + ";" + os.environ['PATH'] _lib = cdll.LoadLibrary(find_library("libopenslide-0.dll"))

Thanks for your answer ! After i modify the lowlevel.py as your solution ,but my spyder still can't import openslide because of OSError: [WinError 127] . I think maybe there is something wrong in my system that i can't find.

Did you download the openslide bin to your system?

Yes. I download the openslide bin in D:\openslide-win64-20171122\bin, add environment path to system and also modify the lowlevel.py . In the end , i can import openslide in cmd normally ,but the spyder can't work.

@huangjin520
Copy link

OS: Windows 10
Python: Anaconda, Python 3.8.5
I think the problem is with the library 'zlib1.dll'. I tried to run find_library(libopenslide-0) and it located the library perfectly fine. But even with addition of os['PATH'] = path-to-openslide-bin" + ";" + os.environ['PATH'] the location for the zlib1.dll is Intel\WiFI\bin.
I solved the issue by adding, the following lines to the lowlevel.py file in , site-packages/openslide/
import os
os.add_dll_directory('PATH_TO_MY_OPENSLIDE_BINARY')

Thank you, this worked perfectly!

Is there someone encounter the bug--(AttributeError: module 'os' has no attribute 'add_dll_directory') , when solve OSError: [WinError 127] in lowlevel.py . I need help for this problem ,why this happen and how to solve it.

@krish78
Copy link

krish78 commented Mar 29, 2023

At the end, I had to clear variables in ipython kernel to get it working in spyder.

@MichaelSchroter
Copy link

MichaelSchroter commented Oct 24, 2023

Hi.
I have the same problem and getting an error as below:

>>> import openslide Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\micha\ML1\Lib\site-packages\openslide\__init__.py", line 31, in <module> from openslide import lowlevel File "C:\Users\micha\ML1\Lib\site-packages\openslide\lowlevel.py", line 32, in <module> os.environ['PATH'] = r'C:\Users\micha\Downloads\openslide-win64-20231011\openslide-win64-20231011\bin' + ';' + os.environ['PATH']

NameError: name 'os' is not defined

Would anyone be able to help me in this matter please.

Thanks & Best Regards

Michael

@bgilbert
Copy link
Member

See the OpenSlide Python installation instructions for the currently recommended way to point OpenSlide Python to the OpenSlide DLL on Windows. It shouldn't be necessary to modify the OpenSlide Python source code.

The The specified procedure could not be found error originally reported in this issue shouldn't be possible with the unified DLL in recent OpenSlide Windows builds. If you're still seeing that message with recent builds, please open a new issue.

@openslide openslide locked as resolved and limited conversation to collaborators Oct 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests