"ImportError: cannot import name urandom", virtualenv is not installed - python

I am running ubuntu 11.10 with python 2.7.2. When I import the random module I get the error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/random.py", line 47, in <module>
from os import urandom as _urandom
ImportError: cannot import name urandom
Googling shows that this appears to be a common problem among people using virtualenv. The solution usually proposed is to simply re-run virtualenv on the directory you're having trouble with. However, I do not have virtualenv installed. Could anyone offer me any guidance as to what to do?
I have looked at ImportError: cannot import name "urandom"; it did not help, since I do not have virtualenv installed (my $ENV is empty, just in case anyone was curious).
I have also looked at Python ImportError cannot import urandom Since Ubuntu 12.04 upgrade; it also did not help, since I am not using virtualenv.
Thanks in advance!

Related

No module named '_gdbm'

I don't know much about python and I need help to install a python software.
I am using linux mint 12.8.
Since I have tried many things I think I have several versions of python installed (3.5 and 3.7 I think...).
When I run setup.py install I get:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 7, in <module>
import dbm.gnu as gdbm
File "/home/zach/10_Soft/anaconda3/lib/python3.7/dbm/gnu.py", line 3, in <module>
from _gdbm import *
ModuleNotFoundError: No module named '_gdbm'
I tried to install python3.5-gdbm (which appears to be up to date) and python3.7-gdbm (which is not found).
They both seem to be virtual packages of the same package python3-gdbm. I don't really know what to do with this information however...
Do you know what I should do?
I was able to solve this issue using this command:
sudo cp /usr/lib/python3.5/lib-dynload/_gdbm.cpython-35m-x86_64-linux-gnu.so /usr/lib/python3.7/lib-dynload/_gdbm.cpython-37m-x86_64-linux-gnu.so

Why won't Python recognize that PyPDF2 is installed?

I'm trying to import PyPDF2 and it won't work. I installed it using pip, then tried it with pip3, it is installed. When I try to import I get the error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'PyPDF2'
I'm using Python 3.7. I found a similar issue here, doesn't seem any of the answers worked and I tried them myself to the same results.
If anyone else runs into this problem try using sys.path to find the site-packages directory. I copied my PyPDF2 packages into my Python37 directory and now it works.

Ubuntu 16.04 Python Version Management Issue

I have Python3.5 and Python3.6 installed on Ubuntu 16.04. I have installed pip for 3.6 and am using 3.6 for development. I tried to install a package (wordcloud) in 3.6 and it appeared to install correctly but I get the following error message:
Traceback (most recent call last):
File "/mnt/data/projects/CSC594/HW01/CSC594-DMARKS-HW01-WordCloud.py", line 11, in <module>
import wordcloud as wc
File "/usr/local/lib/python3.6/dist-packages/wordcloud/__init__.py", line 1, in <module>
from .wordcloud import (WordCloud, STOPWORDS, random_color_func,
File "/usr/local/lib/python3.6/dist-packages/wordcloud/wordcloud.py", line 19, in <module>
from PIL import Image
File "/usr/lib/python3/dist-packages/PIL/Image.py", line 66, in <module>
from PIL import _imaging as core
ImportError: cannot import name '_imaging'
I am not sure what is happening but, python3 is a symbolic link to python3.5 yet when I execute the code, I am calling it in python3.6. Everything looks fine except when it calls the PIL package. PIL is actually installed in 3.6, but not 3.5.
I don't understand why it switches from:
/usr/local/lib/python3.6/dist-packages
to:
/usr/lib/python3/dist-packages
Why does this happen and how do I resolve this situation?
Trusty offers a 3.5 setup, and that won't change. It may be possible to have the two coexist in the way you suggest, but you are finding it challenging. Recommend deleting your python3.6. (Or switching to an ubuntu based on 3.6.)
Install miniconda3, and use that to provide python3.6, PIL, and friends. Very clean. You'll be glad you did.

ImportError: No module named tornado.wsgi

I am running python 2.7 on ubuntu 12.04. I did pip install tornado in a virtual environment and python reports that it was a successful installation. But when I run the code in the file tserver.py I get the following error:
(venv)$ python tserver.py
Traceback (most recent call last):
File "tserver.py", line 1, in <module>
from tornado.wsgi import WSGIContainer
ImportError: No module named tornado.wsgi
I found this question describing a very similar problem Python Tornado: WSGI module missing? -- but my file is not called tornado.py so the answer does not help me.
Had you named the server file initially as tornado.py ? because, I had and even after changing i still got that error.
I fixed it after I did a sudo pip install tornado --upgrade
After this i closed the terminal and restarted it. Then, in the python interpreter i tried import tornado and the error was gone.
Also also remove any tornado.pyc or tornado.py file in the directory where your application is present

"Expected in: flat namespace" error when importing networkx in python

I'm getting a strange error which I can't make sense of.
On Python 2.7, I installed the py27-networkx package using MacPorts. When I try to import networkx as nx, I get the error below. The only line in my network.py file is the import one.
Any ideas on how to debug this to work out what's happening?
Traceback (most recent call last):
File "network.py", line 1, in <module>
import networkx
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/networkx/__init__.py", line 43, in <module>
from networkx import release
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/networkx/release.py", line 45, in <module>
import subprocess
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 427, in <module>
import select
ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/select.so, 2): Symbol not found: __PyInt_AsInt
Referenced from: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/select.so
Expected in: flat namespace
in /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/select.so
Update
Ran a few pieces to help diagnose. Hope it helps someone provide some insight and a solution to this for me.
which python gives me /opt/local/bin/python (I have the standard Mac OS X python, but am using a MacPorts installed version of python2.7)
Running import networkx from the python prompt produces no errors
Anything else I can try?
I also had this error and i fixed by upgrading python27 with macports.
Update macports to the latest version:
sudo port selfupdate
List outdated packages (python27 was outdated for me, when I was getting the import error):
sudo port outdated
Update the outdated packages:
sudo port upgrade outdated

Categories