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

Python3.10 breaks GoldenHinges #5

Open
mcrone opened this issue Feb 24, 2023 · 7 comments
Open

Python3.10 breaks GoldenHinges #5

mcrone opened this issue Feb 24, 2023 · 7 comments
Assignees

Comments

@mcrone
Copy link

mcrone commented Feb 24, 2023

There seems to be an implicit call of from collections import Sequence in the code. This works up until Python3.9, but then returns the error ImportError: cannot import name 'Sequence' from 'collections'.

This is because collections has been renamed to collections.abc and so this can be fixed with import collections.abc as collections in Python3.10.

Found reference to this issue here: https://stackoverflow.com/questions/69596494/unable-to-import-freegames-python-package-attributeerror-module-collections

As I mentioned this seems to be an implicit import as there is no reference to collections in the code of either GoldenHinges or DnaFeaturesViewer.

@veghp
Copy link
Member

veghp commented Feb 24, 2023

Thank you for the notification, I'll look into this. Looks like it can be solved with a simple try except, to keep compatibility with Python 3.6

@veghp veghp self-assigned this Feb 24, 2023
@veghp
Copy link
Member

veghp commented Feb 28, 2023

@mcrone can you please provide the command or a reproducible example that causes the error?

The tests pass in Python 3.10, so I was not able to reproduce the error. I confirm that in v3.10, your example call to collections causes an error, but it's not used in GoldenHinges. Its requirements, proglog, dnachisel and geneblocks, have different imports from collections, but those work too.

@mcrone
Copy link
Author

mcrone commented Mar 1, 2023

@veghp I just ran the example code from the repo:

import collections.abc as collections

from goldenhinges import OverhangsSelector
selector = OverhangsSelector(gc_min=0.25, gc_max=0.5, differences=2,
                             forbidden_overhangs=['ATGC', 'CCGA'])
overhangs = selector.generate_overhangs_set()
print (overhangs)

This is the error:

AttributeError                            Traceback (most recent call last)
/var/folders/zv/39j4sx5x2t3g9m8zb4z0nx740000gp/T/ipykernel_91285/1884757783.py in <module>
      1 import collections.abc as collections
      2 
----> 3 from goldenhinges import OverhangsSelector
      4 selector = OverhangsSelector(gc_min=0.25, gc_max=0.5, differences=2,
      5                              forbidden_overhangs=['ATGC', 'CCGA'])

/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/goldenhinges/__init__.py in <module>
      8 from .biotools import (list_overhangs, gc_content, sequences_differences,
      9                        reverse_complement, load_record)
---> 10 from .reports import (write_report_for_cutting_solution,
     11                       new_sequence_from_cutting_solution)
     12 from .version import __version__

/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/goldenhinges/reports.py in <module>
----> 1 from dna_features_viewer import BiopythonTranslator
      2 import numpy as np
      3 from copy import deepcopy
      4 from Bio import SeqIO
      5 import flametree

/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/dna_features_viewer/__init__.py in <module>
      1 """ dna_features_viewer/__init__.py """
...
-> 1182         return ((isinstance(value, collections.Sequence) or cls._is_seq_like(value)) and
   1183                 not isinstance(value, string_types))
   1184 

AttributeError: module 'collections' has no attribute 'Sequence'

@veghp
Copy link
Member

veghp commented Mar 1, 2023

Thank you. The provided code runs fine for me. I use

Python 3.10.9 (main, Jan 11 2023, 15:21:40) [GCC 11.2.0] on linux
biopython           1.81
dna-features-viewer 3.1.2
goldenhinges        0.2.3

We previously agreed that neither pkg makes a call to collections, and the last error lines are not in either pkg.
Is there any more error trace available? I'd like to find out the origin of line 1182.

Biopython has recently made a possibly related change: https://github.com/biopython/biopython/blob/master/NEWS.rst#18-november-2022-biopython-180
but the last error lines are not in the latest codebase.

I suspect there may be a mismatch between some of the installed packages or Python version. The above installations that worked for me are in a new conda environment. Would updating the packages solve the problem?

@mcrone
Copy link
Author

mcrone commented Mar 6, 2023

Turns out that it was a bokeh problem, I still had an older version that was a dependency of another library.

However, I now have an arm64 problem. I can't install Numberjack because I don't believe Mistral can be compiled for arm64.

ImportError: dlopen(/Users/michaelcrone/Library/Python/3.10/lib/python/site-packages/Numberjack-1.2.1-py3.10-macosx-10.9-universal2.egg/Numberjack/solvers/_Mistral.cpython-310-darwin.so, 0x0002): tried: '/Users/michaelcrone/Library/Python/3.10/lib/python/site-packages/Numberjack-1.2.1-py3.10-macosx-10.9-universal2.egg/Numberjack/solvers/_Mistral.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/michaelcrone/Library/Python/3.10/lib/python/site-packages/Numberjack-1.2.1-py3.10-macosx-10.9-universal2.egg/Numberjack/solvers/_Mistral.cpython-310-darwin.so' (no such file), '/Users/michaelcrone/Library/Python/3.10/lib/python/site-packages/Numberjack-1.2.1-py3.10-macosx-10.9-universal2.egg/Numberjack/solvers/_Mistral.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))

Confirmed working on python3.11 on an x86_64 (my old laptop).

@veghp
Copy link
Member

veghp commented Mar 6, 2023

I'm glad that updating the packages solved the problem. Yes unfortunately Numberjack is an old dependency, and we also test and use for x86 architecture and Ubuntu only. I'll close this one as the original problem is solved, and this is also a separate issue which I see you have filed here: eomahony/Numberjack#62 .

@Zulko
Copy link
Member

Zulko commented Mar 6, 2023

Yeah I'm not sure Numberjack is still maintained unfortunately. There is Google ORTools that looks still active and could do the job (see the end of this page)

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

3 participants