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

py3: relative imports fail #26

Open
endrebak opened this issue May 24, 2016 · 8 comments
Open

py3: relative imports fail #26

endrebak opened this issue May 24, 2016 · 8 comments

Comments

@endrebak
Copy link

(Conda gives a conflicting requirements error, so I installed metaseq with pip.)

When trying to import metaseq, I get the following error:

In [2]: import metaseq
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-3365faa9d779> in <module>()
----> 1 import metaseq

/local/home/endrebak/anaconda3/lib/python3.5/site-packages/metaseq/__init__.py in <module>()
      2 import sys
      3 import time
----> 4 import helpers
      5 from helpers import data_dir, example_filename
      6 from _genomic_signal import genomic_signal

ImportError: No module named 'helpers'
@endrebak
Copy link
Author

endrebak commented May 24, 2016

If I am reading your Travis build log correctly, you only test on py27. Is this a requirement? If so, I guess I cannot use metaseq with snakemake as easily as I hoped. And you should add the requirement to your docs/README.md.

Pretend edit: tested conda install metaseq-all on py27 and it imports just fine.

@endrebak
Copy link
Author

Relative imports were removed in py3 (good choice, imo), and this is why it fails. I fixed your metaseq/__init__.py like so:

import os
import sys
import time
from metaseq import helpers
from metaseq.helpers import data_dir, example_filename
from metaseq._genomic_signal import genomic_signal
import metaseq.plotutils
import integration
import integration.chipseq
import metaseq.colormap_adjust
import metaseq.results_table
import metaseq.tableprinter
from metaseq.version import __version__
import metaseq.persistence

but then I got this error:

In [1]: import metaseq
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-3365faa9d779> in <module>()
----> 1 import metaseq

/local/home/endrebak/anaconda3/lib/python3.5/site-packages/metaseq-0.5.6-py3.5.egg/metaseq/__init__.py in <module>()
      4 from metaseq import helpers
      5 from metaseq.helpers import data_dir, example_filename
----> 6 from metaseq._genomic_signal import genomic_signal
      7 import metaseq.plotutils
      8 import integration

/local/home/endrebak/anaconda3/lib/python3.5/site-packages/metaseq-0.5.6-py3.5.egg/metaseq/_genomic_signal.py in <module>()
     30
     31 import numpy as np
---> 32 from bx.bbi.bigwig_file import BigWigFile
     33
     34 import pybedtools

bx/bbi/bigwig_file.pyx in init bx.bbi.bigwig_file (lib/bx/bbi/bigwig_file.c:7691)()

bx/bbi/bbi_file.pyx in init bx.bbi.bbi_file (lib/bx/bbi/bbi_file.c:12911)()

ImportError: No module named 'cStringIO'

which I do not have time to look up now, but I'd guess it has to do with the same import issue.

@endrebak endrebak changed the title No module named 'helpers' py3: relative imports fail May 24, 2016
@daler
Copy link
Owner

daler commented May 24, 2016

Yep, due to the dependency on bx-python, which itself is only py27, I can't make metaseq py3-compatible.

Whenever I need to use it within snakemake, I end up writing a separate script and run it in a py27 env. Awkward? Yes.

I think the best solution here is to replace bx-python with the py3-compatible pybigwig. That will require a bit of work and lots more tests. It's already on my list though.

That said, depending on what you need to do, deepTools might be a better option than metaseq.

@endrebak
Copy link
Author

bx-python has actually been python3 compatible for a year or so, IIRC. Perhaps you should try installing it again?

But do not put this high on your todo-list for my sake, I'll easily find a workaround.

@daler
Copy link
Owner

daler commented May 24, 2016

The error you reported is a common error in non-py3-compatible code and, judging from your paths, is coming from bx-python as installed under py35. I had also tried building it a few months ago for py3 in bioconda and didn't have any luck. Are you able to use the bx.bbi.bigwig_file module in py3?

@endrebak
Copy link
Author

Sorry, probably not! I always think bx = intervaltree, clustertree because
it is the only two modules I use.

On Tue, May 24, 2016 at 3:46 PM, Ryan Dale notifications@github.com wrote:

The error you reported is a common error in non-py3-compatible code and,
judging from your paths, is coming from bx-python as installed under py35.
I had also tried building it a few months ago for py3 in bioconda and
didn't have any luck. Are you able to use the bx.bbi.bigwig_file module
in py3?


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#26 (comment)

@endrebak
Copy link
Author

endrebak commented May 25, 2016

When I learn more about bigwig, I'll try out https://bitbucket.org/mruffalo/bx-python3 and see if it works.

Perhaps it can be bundled with metaseq? It probably will not get more updates, but might be good enough.

@superbobry
Copy link

superbobry commented May 25, 2016

I think it might be more beneficial to port the original bx-python (which I believe is bxlab/bx-python) to Python3 rather than switching to an unmaintained fork.

@endrebak you could get Python3 behaviour in Python2 by importing

from __future__ import absolute_import

After this import the following

import metaseq.colormap_adjust
import metaseq.results_table
import metaseq.tableprinter

could be concisely written as

from . import colormap_adjust, results_table, tableprinter

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