0

I have created a shared object file "myFile.so" that I am able to load and use via ctypes using the base anaconda environment without issue.

For example, I have no problem doing the following:

import ctypes
clibrary = ctypes.CDLL(r"C:\Users\FirstName LastName\Documents\Project\myFile.so")
clibrary.doThings(ctypes.c_int(10), ctypes.c_float(0.6))

However, when I activate a virtual environment "testEnvironment" and use the same code I get the following error:

FileNotFoundError: Could not find module 'C:\Users\FirstName LastName\Documents\Project\myFile.so' (or one of its dependencies). Try using the full path with constructor syntax.

Since the problem seems to involve the way in which anaconda environments search for things, I tried copying the value of os.environ["PATH"] from my base environment to the testEnvironemnt, but received the same error after running the code. I also tried navigating directly to the folder where the file "myFile.so" is located and running the code from there, but again no luck.

Update

The base python environment was using python version 3.8.5, while the virtual environment was using python version 3.10.6. I created a new virtual environment using python version 3.8.5 and the above code ran without issue. Therefore the problem appears to be related a change that has occurred between these python versions rather than something related to anaconda environments.

Update 2

I still have not found a way to solve the problem in version 3.10.6. However, I also tested version 3.9.15 and the code ran without issue.

George
  • 23
  • 4
  • 1
    How did you build your file? What are the *Python* versions involved? Why didn't you name it *myFile.dll*? – CristiFati Nov 13 '22 at 18:10
  • @CristiFati thanks for your response. It looks like the virtual environment is a newer version of python (3.10.6) versus 3.8.5 for the base environment. I just tested creating another environment with python version 3.8.5, and this environment is able to run the code without issue like the base environment. It seems like there has been a change between these two versions of python. I believe my question is now reduced to: "what is the correct way to do this in python 3.10?" – George Nov 13 '22 at 18:37
  • Strange. I can't reproduce. Maybe the environment is messed up (or there's something with your file - can you share it?)? Also I asked 2 questions that didn't get answered. Maybe [\[SO\]: PyWin32 and Python 3.8.0 (@CristiFati's answer)](https://stackoverflow.com/a/58632354/4788546) will help. – CristiFati Nov 18 '22 at 07:17

0 Answers0