TL;DR https://qrunch.net/@sugurunatsuno/entries/wF9aXWZ3x3PBarLR Add the directory containing the pyd file you want to read to PYTHONPATH.
I can't load my pyd file when I run a Django project using IIS. As a result, the environment variable PYTHONPATH did not have a directory that could refer to the pyd file. I was able to import the pyd file when I ran it on Django's runserver. It is assumed that IIS will work except for importing pyd files.
OS/software/Library name | version |
---|---|
Windows | 10 |
IIS | 10 |
Python | 3.8.0 |
Django | 2.2.8 |
Cython | 0.29.15 |
It only needs to be set in either IIS or Python. In IIS, environment variables can be set with web.config etc. You can set multiple paths separated by semicolons, so add the path where the pyd file is located.
<add key="PYTHONPATH" value="project_path;pyd_absolute_path" />
Since the import of the pyd file in this case refers to PYTHONPATH, it is not a relative path from the py file to be called.
#Cannot be referenced by relative path
# from pyd_relative_path import target
#Since it is set in PYTHONPATH, it can be called as it is
import target
It only needs to be set in either IIS or Python. Environment variables can also be set on python, so you can set the directory where the pyd file is located.
import os
import sys
current_dir = os.path.abspath(os.path.dirname(__file__))
sys.path += [os.path.join(current_dir, 'pyd_relative_path')]
import target
Recommended Posts