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

python setup.py build_ext error: Cython.Compiler.Errors.CompileError: parse_bed.pyx #81

Open
bensutherland opened this issue Jan 5, 2024 · 7 comments

Comments

@bensutherland
Copy link

I am having trouble installing fastStructure (cloned today) on a MacOS (Ventura 13.5). I've followed all instructions from the README, and have installed all necessary dependencies. I can give details if needed, or if that would help please let me know.

The crash occurs when trying to compile the main cython scripts.
Error message:

$ python setup.py build_ext --inplace
running build_ext
Compiling parse_bed.pyx because it changed.
[1/1] Cythonizing parse_bed.pyx
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Cython/Compiler/Main.py:381:
FutureWarning: Cython directive 'language_level' not set, using '3str' for now
(Py3). This has changed from earlier releases! File:
/Users/bens/programs/fastStructure/parse_bed.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)

Error compiling Cython file:
------------------------------------------------------------
...
    checkB = bin(struct.unpack('<B', line)[0])[2:].zfill(8)[::-1]
    line = handle.read(1)
    checkC = bin(struct.unpack('<B', line)[0])[2:].zfill(8)[::-1]

    if checkA!="00110110" or checkB!="11011000":
        print "This is not a valid bed file"
              ^
------------------------------------------------------------

parse_bed.pyx:47:14: Syntax error in simple statement list
Traceback (most recent call last):
  File "setup.py", line 15, in <module>
    ext_modules = ext_modules
  File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py",
line 151, in setup
    dist.run_commands()
  File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py",
line 953, in run_commands
    self.run_command(cmd)
  File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py",
line 972, in run_command
    cmd_obj.run()
  File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/build_ext.py",
line 340, in run
    self.build_extensions()
  File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/build_ext.py",
line 449, in build_extensions
    self.build_extension(ext)
  File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Cython/Distutils/build_ext.py",
line 131, in build_extension
    ext,force=self.force, quiet=self.verbose == 0, **options
  File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Cython/Build/Dependencies.py",
line 1154, in cythonize
    cythonize_one(*args)
  File
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Cython/Build/Dependencies.py",
line 1321, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: parse_bed.pyx

Some details:
python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2
GSL-2.7 installed from gnu.org
numpy installed by pip
Cython installed by pip
/Library/Frameworks/Python.framework/Versions/2.7/bin/Cython

Thank you for any help.

@alleneli
Copy link

I'm having the exact same problem, was a solution found?

@bensutherland
Copy link
Author

Hi @alleneli , Unfortunately no, I did not find a solution, and was not able to get the program to install.

@alleneli
Copy link

Shoot, I tried reverting to an older version of Cython that tends to work better with Python 2, but that led to another suite of issues.

If I make any progress I will report back here.

@pkmnsandy
Copy link

I found a workaround, someone created this: https://structure-threader.readthedocs.io/en/latest/ and it works perfectly in my M1 Mac.

@alleneli
Copy link

Awesome, thank you @pkmnsandy!

@David919110
Copy link

in parse_bed.pyx you need to put : Nbytes = Nindiv//4+(Nindiv%4>0)*1 (double //), not Nbytes = Nindiv/4+(Nindiv%4>0)*1, then in each .py file put print ( ), i.e. parentheses in each print

@ntakebay
Copy link

ntakebay commented Aug 15, 2024

Original poster was using python 2, but if you are using python 3, you can try https://github.com/jashapiro/fastStructure/tree/py3 This fix wasn't incorporated into the main branch. But even with this py3 branch, I had to fix a couple additional things which David919110 suggested (missing parentheses for print () in fastStructure.pyx and parse_bed.pyx and specify integer division // instead of / in parse_bed.pyx. Here is the patch:
fastStructure-py3.print.intDiv.patch
:

diff -ru fastStructure-19e39d1161c2eb49e6137d2ab2449888bd04f7ec.orig/fastStructure.pyx fastStructure-19e39d1161c2eb49e6137d2ab2449888bd04f7ec/fastStructure.pyx
--- fastStructure-19e39d1161c2eb49e6137d2ab2449888bd04f7ec.orig/fastStructure.pyx       2015-10-15 12:34:35.000000000 -0800
+++ fastStructure-19e39d1161c2eb49e6137d2ab2449888bd04f7ec/fastStructure.pyx    2024-08-14 15:07:09.923564488 -0800
@@ -302,7 +302,7 @@
 
         if not len(newmasks)>=cv:
             wellmasked = False
-            print "Failed"
+            print("Failed")
 
     masks = newmasks[:cv]
     meandeviance = np.zeros((cv,), dtype=float)
diff -ru fastStructure-19e39d1161c2eb49e6137d2ab2449888bd04f7ec.orig/parse_bed.pyx fastStructure-19e39d1161c2eb49e6137d2ab2449888bd04f7ec/parse_bed.pyx
--- fastStructure-19e39d1161c2eb49e6137d2ab2449888bd04f7ec.orig/parse_bed.pyx   2015-10-15 12:34:35.000000000 -0800
+++ fastStructure-19e39d1161c2eb49e6137d2ab2449888bd04f7ec/parse_bed.pyx        2024-08-14 15:07:17.109669878 -0800
@@ -22,7 +22,7 @@
     Nindiv = i+1
 
     # Number of bytes to read in at a time
-    Nbytes = Nindiv/4+(Nindiv%4>0)*1
+    Nbytes = Nindiv//4+(Nindiv%4>0)*1
 
     # number of SNPs
     handle = open(file+'.bim','r')
@@ -45,7 +45,7 @@
     checkC = bin(struct.unpack('<B', line)[0])[2:].zfill(8)[::-1]
 
     if checkA!="00110110" or checkB!="11011000":
-        print "This is not a valid bed file"
+        print("This is not a valid bed file")
         handle.close()
         sys.exit(2)



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants