Open brunkowacodes opened 11 months ago
Hello, I faced the same issue and solved it. It seems that if you are using Python 3, you need to import like this:
from .basic_euclidean import c_point_to_trajectory
instead of
from basic_euclidean import c_point_to_trajectory
https://copyprogramming.com/howto/module-not-found-error-when-importing-a-cython-pyd-file
So, in sspd.pyx and all other .pyx files in cydist directory, just add a dot . before every basic_euclidean and basic_geographical import. Hope this helps.
Hey, I don't know if someone still reads this, but I'm trying to run this package in python 3.10.
I installed it, via
Git clone
- Inserting a cast to an int in the last function in frechet (line 534..), because it didnt compile:
while(len(cc)!=1): m_i=int(len(cc)/2-1) eps = cc[m_i] rep = _decision_problem(P,Q,p,q,eps) if rep: cc=cc[:m_i+1] else: cc=cc[m_i+1:] return eps
- Inserting some requires into pyproject.toml, as in this issue :
[build-system] requires = [ "setuptools", "Cython>=0.27.3", # Note: sync with setup.py "numpy" ] build-backend = "setuptools.build_meta"
python setup.py install
pip install .
With the changes, the installation seems to work. But when I try to import the distance module via
import traj_dist.distance as tdist
I get the following error:(synth_privacy_evaluation) ➜ privacyrisk git:(main) ✗ python example.py Traceback (most recent call last): File "/Users/alex/PycharmProjects/synth_privacy_evaluation/privacyrisk/example.py", line 12, in <module> import privrisk File "/Users/alex/PycharmProjects/synth_privacy_evaluation/privacyrisk/privrisk.py", line 10, in <module> import traj_dist.distance as tdist File "/Applications/anaconda3/envs/synth_privacy_evaluation/lib/python3.10/site-packages/traj_dist/distance.py", line 3, in <module> from .cydist.sspd import c_e_sspd, c_g_sspd File "traj_dist/cydist/sspd.pyx", line 8, in init traj_dist.cydist.sspd ModuleNotFoundError: No module named 'basic_euclidean'
I tried to change the imports and add paths manually, but that didn't work either. So if you could help me, that would be really nice!
Did it work out for you? I tried add dot as the next blog suggested, however, it reported the same error.
Did it work out for you? I tried add dot as the next blog suggested, however, it reported the same error.
Hey, iirc it didn't and we "solved" it by using the normal python code instead of the cython files. That worked, but I guess with worse performance.
Did it work out for you? I tried add dot as the next blog suggested, however, it reported the same error.
Hey, iirc it didn't and we "solved" it by using the normal python code instead of the cython files. That worked, but I guess with worse performance.
hello @brunkowacodes , I’m encountering some problems and have modified the code as mentioned, but it still doesn’t work. Could you please explain how you use the normal python code instead of the cython files? Thank you very much!
Hello @moxingwen , I have collocted some bug fix methods. Share them with you here.
git clone https://github.com/bguillouet/traj-dist.git
to local to install manually.
python setup.py install
# or pip install .
Maybe we miss Cython package.
conda install Cython
# or pip install Cython
Error compiling Cython file:
------------------------------------------------------------
...
q=len(Q)
cc=_compute_critical_values(P,Q,p,q)
eps=cc[0]
while(len(cc)!=1):
m_i=len(cc)/2-1
^
------------------------------------------------------------
traj_dist/cydist/frechet.pyx:535:21: Cannot assign type 'double' to 'int'
......
File ".../site-packages/Cython/Build/Dependencies.py", line 1134, in cythonize
cythonize_one(*args)
File ".../site-packages/Cython/Build/Dependencies.py", line 1301, in cythonize_one
raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: traj_dist/cydist/frechet.pyx
change to m_i=len(cc)//2-1
It indicate that this library requires to install Microsoft Visual C++ 14.0 or greater. To install that, we need to go https://visualstudio.microsoft.com/visual-cpp-build-tools/ and download the program, then install Workload named Desktop development C++
(may plus .NET desktop development
), install the core and their optional files.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "traj_dist/distance.py", line 13, in <module>
from .cydist.sspd import c_e_sspd, c_g_sspd
ModuleNotFoundError: No module named 'traj_dist.cydist.sspd'
sspd
need be compiled from .pyx
into .so
or .pyd
.
Use command below to compile them.
python setup.py build_ext --inplace
--inplace
: ignore build-lib and put compiled extensions into the source directory alongside your pure Python modules.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "traj-dist/traj_dist/distance.py", line 3, in <module>
from .cydist.sspd import c_e_sspd, c_g_sspd
File "traj_dist/cydist/sspd.pyx", line 8, in init traj_dist.cydist.sspd
from basic_euclidean import c_point_to_trajectory
ModuleNotFoundError: No module named 'basic_euclidean'
check every file with suffix of .pyx
in cydist, and add .
ahead of basic_euclidean
or basic_geographical
to make the relative import instead of absolute import.
Then re-compile them
python setup.py build_ext --inplace
After fixing bugs, python setup.py install
again.
Hello @moxingwen , I have collocted some bug fix methods. Share them with you here.
Bug fix record
git clone https://github.com/bguillouet/traj-dist.git
to local to install manually.
python setup.py install # or pip install .
Maybe we miss Cython package.
conda install Cython # or pip install Cython
CompileError caused by type conversion error
Error compiling Cython file: ------------------------------------------------------------ ... q=len(Q) cc=_compute_critical_values(P,Q,p,q) eps=cc[0] while(len(cc)!=1): m_i=len(cc)/2-1 ^ ------------------------------------------------------------ traj_dist/cydist/frechet.pyx:535:21: Cannot assign type 'double' to 'int' ...... File ".../site-packages/Cython/Build/Dependencies.py", line 1134, in cythonize cythonize_one(*args) File ".../site-packages/Cython/Build/Dependencies.py", line 1301, in cythonize_one raise CompileError(None, pyx_file) Cython.Compiler.Errors.CompileError: traj_dist/cydist/frechet.pyx
change to
m_i=len(cc)//2-1
error: Microsoft Visual C++ 14.0 or greater is required. during pip install
It indicate that this library requires to install Microsoft Visual C++ 14.0 or greater. To install that, we need to go https://visualstudio.microsoft.com/visual-cpp-build-tools/ and download the program, then install Workload named
Desktop development C++
(may plus.NET desktop development
), install the core and their optional files.ModuleNotFoundError
caused by no compilation
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "traj_dist/distance.py", line 13, in <module> from .cydist.sspd import c_e_sspd, c_g_sspd ModuleNotFoundError: No module named 'traj_dist.cydist.sspd'
sspd
need be compiled from.pyx
into.so
or.pyd
.Use command below to compile them.
python setup.py build_ext --inplace
--inplace
: ignore build-lib and put compiled extensions into the source directory alongside your pure Python modules.caused by absolute import in .pyx files
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "traj-dist/traj_dist/distance.py", line 3, in <module> from .cydist.sspd import c_e_sspd, c_g_sspd File "traj_dist/cydist/sspd.pyx", line 8, in init traj_dist.cydist.sspd from basic_euclidean import c_point_to_trajectory ModuleNotFoundError: No module named 'basic_euclidean'
check every file with suffix of
.pyx
in cydist, and add.
ahead ofbasic_euclidean
orbasic_geographical
to make the relative import instead of absolute import.Then re-compile them
python setup.py build_ext --inplace
After fixing bugs,
python setup.py install
again.
@ronnychou Thank you
Hey, I don't know if someone still reads this, but I'm trying to run this package in python 3.10.
I installed it, via
Git clone
Inserting a cast to an int in the last function in frechet (line 534..), because it didnt compile:
Inserting some requires into pyproject.toml, as in this issue :
python setup.py install
pip install .
With the changes, the installation seems to work. But when I try to import the distance module via
import traj_dist.distance as tdist
I get the following error:I tried to change the imports and add paths manually, but that didn't work either. So if you could help me, that would be really nice!