Ubuntu 16.04 Python Version Management Issue - python

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.

Related

Not able to import Python packages

Not able to install any packages
I've tried VLC package from https://wiki.videolan.org/python_bindings
and got a traceback.
Now I am trying pygame module and this is what i get
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import pygame
File "C:\Users\Vineeth\AppData\Local\Programs\Python\Python36-32\lib\pygame\__init__.py", line 133, in <module>
from pygame.base import *
ImportError: DLL load failed: The specified module could not be found.
Please help i am pretty new to python
There are some release binaries for Python3.x, 64bit Windows at http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame
I suggest you download it from that site and install it. It works for me. If you are using Windows ,it is a good way to install some packages,like lxml matplotlib.
Also you check out this question.
Hope this helps.
I tried to execute your statements and the imports worked fine for me. I have a 64bit Windows OS. And my python version Python 3.5.2 - 64bit.
Check if you have other Python versions, if you have removed them, make sure you did that right.
Ultimately I would just suggest you to do pip install pygame. The version compatibility will be handled by pip itself.

Using Kivy with Python 3.4

I have installed Kivy on my Mac. OS X comes installed with Python 2.7. I wanted to use the enum feature of Python 3, so I installed Python 3.4. After much searching and oulling of hair, I was pointed to this line
exec $(python -c "import os, sys; print os.path.normpath(sys.prefix)")/bin/python2.7 "$#"
in the file /Applications/Kivy.app/Contents/Resources/script. I changed it to:
exec /Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 "$#"
in the hope of forcing Kivy to use Python 3.4.
I now get this error:
Traceback (most recent call last):
File "main.py", line 1, in <module>
from kivy.app import App
File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/app.py", line 321, in <module>
from kivy.base import runTouchApp, stopTouchApp
File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/base.py", line 29, in <module>
from kivy.event import EventDispatcher
File "/Applications/Kivy.app/Contents/Resources/kivy/kivy/event.py", line 8, in <module>
import kivy._event
ImportError: dlopen(/Applications/Kivy.app/Contents/Resources/kivy/kivy/_event.so, 2): Symbol not found: _PyString_Type
Referenced from: /Applications/Kivy.app/Contents/Resources/kivy/kivy/_event.so
Expected in: flat namespace
in /Applications/Kivy.app/Contents/Resources/kivy/kivy/_event.so
Can anyone help in fixing this error? Or is there a better way to get Kivy to use Python 3.4?
I have installed Kivy 1.8.0.
I am running the app from the terminal, e.g.
kivy main.py
This line:
dlopen(/Applications/Kivy.app/Contents/Resources/kivy/kivy/_event.so, 2)
Is trying to open a shared object, which would have been compiled for the explicit version of Python that your install of Kivy was intended for.
Any Python package that includes precompiled dependencies will only work for the version of Python they were compiled against.
Kivy has not yet been tested with Python 3.4. It runs fine with Python 3.3.
I've gotten kivy working on OSX El Capitan with Python 3.5. Here's how I did it.
You will need to brew install the dependencies, then modify setup.py to use the brew installed dependencies. The default setup.py will look to your frameworks directory, but that's not where brew puts the new files!
I was able to install kivy for python 3.5. I didn't have to do anything extra, just regular install kivy and it is working.

"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

I'm unable to compile Phoenix on OSX (10.6.7)

Using python that's installed by default on OSX, I'm trying to run phoenix
https://en.bitcoin.it/wiki/Phoenix_miner
and I'm getting:
python phoenix.py
import itertools, md5
Traceback (most recent call last):
File "phoenix.py", line 29, in <module>
import minerutil
File "/Users/george/Downloads/phoenix-1.4/minerutil/__init__.py", line 25, in <module>
from RPCProtocol import RPCClient
File "/Users/george/Downloads/phoenix-1.4/minerutil/RPCProtocol.py", line 30, in <module>
from twisted.web.iweb import IBodyProducer
ImportError: cannot import name IBodyProducer
Can anyone advise how to proceed?
You probably have to upgrade your version of Twisted. 11.0 should work; it did for me. Try
sudo easy_install --upgrade twisted
[This assumes that easy_install is going to pick up the system python. If it's in a weird state, try sudo python_version path_to_easy_install --upgrade twisted.]
I installed MacPorts, installed python27 to /opt/local/bin/python, downloaded the Twisted-11.0.0 source, and compiled it using python27. I compiled and installed pyopencl from source as well, and now I can run phoenix.py, on Mac 10.6.6.

MySQLdb for Python - incompatible library version error?

I am, like many others, trying to get MySQLdb for Python to run on Mac Snow Leopard (10.6.x) and I've been able to install the 64-bit MySQL DMG as recommended by various blogs/forum posts, and I've been able to install the setuptools and MySQLDB itself by using the
ARCHFLAGS='-arch 86_64' python2.7 setup.py clean
ARCHFLAGS='-arch 86_64' python2.7 setup.py build
sudo ARCHFLAGS='-arch 86_64' python2.7 setup.py install
As you can see from the above I have upgraded to Python 2.7 and everything seems fine; except when I try to import MySQLdb into python shell.
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.macosx-10.6-universal/egg/MySQLdb/__init__.py", line 19, in <module>
File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 7, in <module>
File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/ad/.python-eggs/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 2): Library not loaded: /usr/local/mysql/lib/libmysqlclient.16.dylib
Referenced from: /Users/ad/.python-eggs/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so
Reason: Incompatible library version: _mysql.so requires version 17.0.0 or later, but libmysqlclient.16.dylib provides version 16.0.0
I did a search and found libmysqlclient.16.dylib but not libmysqlclient.17.dylib
What is causing this problem, how do I resolve it, and even though I did a search for libmysqlclient.17.dylib there seems to be nothing about it; does it exist?
Thanks
You built the module against MySQL 5.5.x, but only the client libraries for 5.1.x are available on the system. Either install updated libraries, or build against an older version.
Definitely make sure that Python and MySQL are for the same architecture. You have to consistently use either 32bit or 64bit versions for both.
Also make sure that MySQLdb can find the MySQL libraries and includes, but from your error message it seems like this is the case.

Categories