Python Error: IPython.display import Markdown as display - python

I am trying to use the pydna module on a machine running Ubuntu 14.04, and am getting the following error when I try to import it:
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pydna/__init__.py", line 97, in <module>
from pydna.amplify import Anneal
File "/usr/local/lib/python2.7/dist-packages/pydna/amplify.py", line 32, in <module>
from pydna.dsdna import rc
File "/usr/local/lib/python2.7/dist-packages/pydna/dsdna.py", line 63, in <module>
from IPython.display import Markdown as display
ImportError: cannot import name Markdown
Has anyone found a way to resolve this? I have tried reinstalling IPython, and pydna. The offending chunk in dsdna.py is the following:
(lines 58-63)
try:
import IPython
except ImportError:
def display(item): return item
else:
from IPython.display import Markdown as display
Any help would be greatly appreciated!
(Python 2.7.6)

I have the IPython 4.1.1 installed and it works for me (see below). Which version do you have? Also, which pydna version did you install?
This could be due to a too old version of IPython, recently IPython was split into IPython and Jupyter which caused some code to break.
(bjorn)bjorn#bjorn-ThinkPad-T450s:~/Desktop/GMB$ python
Python 2.7.10 |Anaconda 2.5.0 (64-bit)| (default, Oct 19 2015, 18:04:42)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> from IPython.display import Markdown as display
>>> import IPython
>>> IPython.__version__
'4.1.1'

Related

Can't import cElementTree on Python 2.7

I cannot import xml.etree.cElementTree on Python 2.7. On the web, it says its already implemented, so I don't have to install it. (It's working on Python 3.6 for me, but I need 2.7 for reasons here)
Thats the console output:
Python 2.7.15+ (default, Nov 27 2018, 23:36:35)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import xml.etree.cElementTree
Failed to import cElementTree from any known place
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named etree.cElementTree
I hope you can help me.
Kind regards,
Markus
I just found out that theres an old xml.pyc file in that directory, which didnt show up in PyCharm. It stopped the "real" XML from loading.

Unable to load libhdfs

Trying to use pyarrow to access hdfs file and not able to get it working, below is the code, thank you very much in advance.
[rxie#cedgedev03 code]$ python
Python 2.7.12 |Anaconda 4.2.0 (64-bit)| (default, Jul 2 2016, 17:42:40)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
import pyarrow
import os
os.environ["JAVA_HOME"]="/usr/java/jdk1.8.0_121"
from pyarrow import hdfs
fs = hdfs.connect()
Traceback (most recent call last): File "", line 1, in File
"/opt/cloudera/parcels/Anaconda/lib/python2.7/site-packages/pyarrow/hdfs.py",
line 183, in connect extra_conf=extra_conf) File
"/opt/cloudera/parcels/Anaconda/lib/python2.7/site-packages/pyarrow/hdfs.py",
line 37, in init self._connect(host, port, user, kerb_ticket, driver,
extra_conf) File "pyarrow/io-hdfs.pxi", line 89, in
pyarrow.lib.HadoopFileSystem._connect File "pyarrow/error.pxi", line
83, in pyarrow.lib.check_status pyarrow.lib.ArrowIOError: Unable to
load libhdfs
You might need to manually locate this file and specify it with the ARROW_LIBHDFS_DIR environmental variable.
Find the file using locate -l 1 libhdfs.so. In my case, the file is located under /opt/mapr/hadoop/hadoop-0.20.2/c++/Linux-amd64-64/lib.
Then, restart your Python REPL with the environment variable ARROW_LIBHDFS_DIR set to this path. In my case, my command looks like:
ARROW_LIBHDFS_DIR=/opt/mapr/hadoop/hadoop-0.20.2/c++/Linux-amd64-64/lib python
This should solve this particular problem.
(Inspired by https://gist.github.com/priancho/357022fbe63fae8b097a563e43dd885b)

python3 does not allow urllib import

I installed anaconda for Python 3.6 in MacOs Sierra.
It comes with its own python and it changed the default python to this new one.
Now, I am not able to import anything from urllib.
Here is a snippet of my terminal.
Can someone give some suggestions?
devassy#mydire $ python
Python 3.6.5 |Anaconda, Inc.| (default, Apr 26 2018, 08:42:37)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from urllib.request import url2pathname
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/devassy/anaconda3/lib/python3.6/urllib/request.py", line 2585, in <module>
from _scproxy import _get_proxy_settings, _get_proxies
ImportError: dlopen(/Users/devassy/anaconda3/lib/python3.6/lib-dynload/_scproxy.cpython-36m-darwin.so, 2): Symbol not found: _iconv
Referenced from: /usr/lib/libcups.2.dylib
Expected in: /Users/devassy/anaconda3/lib/libiconv.2.dylib
in /usr/lib/libcups.2.dylib
>>>

Anaconda: matplotlib PdfPages import error

I've a problem with importing the PdfPages function from the matplotlib package on my anaconda environment. I get the following error:
Python 2.7.13 |Anaconda 4.4.0 (64-bit)| (default, Dec 20 2016, 23:09:15)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> from matplotlib.backends.backend_pdf import PdfPages
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/hpc/capn/mppi033h/.virtualenv/h5_to_histo_env/lib/python2.7/site-packages/matplotlib/backends/backend_pdf.py", line 32, in <module>
from matplotlib.backend_bases import (RendererBase, GraphicsContextBase,
File "/home/hpc/capn/mppi033h/.virtualenv/h5_to_histo_env/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 63, in <module>
import matplotlib.textpath as textpath
File "/home/hpc/capn/mppi033h/.virtualenv/h5_to_histo_env/lib/python2.7/site-packages/matplotlib/textpath.py", line 17, in <module>
import matplotlib.font_manager as font_manager
File "/home/hpc/capn/mppi033h/.virtualenv/h5_to_histo_env/lib/python2.7/site-packages/matplotlib/font_manager.py", line 1439, in <module>
_rebuild()
File "/home/hpc/capn/mppi033h/.virtualenv/h5_to_histo_env/lib/python2.7/site-packages/matplotlib/font_manager.py", line 1421, in _rebuild
with cbook.Locked(cachedir):
File "/home/hpc/capn/mppi033h/.virtualenv/h5_to_histo_env/lib/python2.7/site-packages/matplotlib/cbook.py", line 2738, in __enter__
files = glob.glob(self.pattern)
AttributeError: 'module' object has no attribute 'glob'
Importing matplotlib (import matplotlib) works fine though. I'm running python in a virtual environment created with Anaconda (/.../.virtualenv/h5_to_histo_env/)
According to conda-V my version is 'conda 4.3.16' and my matplotlib version is 2.0.2 ('np112py27_0').
My Anaconda environment is up to date as well, does anybody know why I get this error?
Update: Reinstalling the virtual anaconda environment and specifying the needed packages at the beginning with the conda create command (and not after the virtual env is already created) fixed it somehow!

Why I can not import the package in Python?

I use the code from here:
https://github.com/Jefferson-Henrique/GetOldTweets-python
And every time I try to import the file folder, import got, it will raise:
Traceback (most recent call last):
File "C:\Users\USER\Desktop\python\get_old_tweet\Main.py", line 1, in <module>
import got
File "C:\Users\USER\Desktop\python\get_old_tweet\got\__init__.py", line 1, in <module>
import models
ImportError: No module named 'models'
I have check the file and been pretty sure that they do have the file folder called models
And the file folder also contains __init__.py file.
So it should work well..
I have no idea how it doesn't work. Please help me!
Which version of Python do you use?
The library https://github.com/Jefferson-Henrique/GetOldTweets-python is written with Python 2.
Python 2 and Python 3 have a bit different behavior with import: https://www.python.org/dev/peps/pep-0404/#imports
Let me share example of import regarding your case:
$ python3
Python 3.5.0 |Anaconda 2.4.0 (x86_64)| (default, Oct 20 2015, 14:39:26)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import got
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/viach/Downloads/GetOldTweets-python-master/got/__init__.py", line 1, in <module>
import models
ImportError: No module named 'models'
>>> ^C
KeyboardInterrupt
$ python2
Python 2.7.10 (default, Aug 22 2015, 20:33:39)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import got
So, quick solution for you: use Python 2 in your app which depends on GetOldTweets-python.
Python only searches its default library paths by default (including the running script path). So you need to put them in Python default library paths or append your module path to those paths.
To append the path array:
>>> import sys
>>> sys.path.append("path/to/the_module")
>>> import the_module
If above solution doesn't worked, try:
>>> from models import got
It depends on where you are importing from. In the repository you proved a link to models is a subfolder of got. Try this:
from got import models
You can use a Python3-compatible fork of GetOldTweets-python:
https://github.com/Mottl/GetOldTweets-python3

Categories