The problem:
I've installed mapnik 3.0.1 successfully by running the typical source code install:
./configure
make && make install
ldconfig -v
However....
When I import mapnik into python I get the following:
Python 2.7.5 (default, Jun 24 2015, 00:41:19)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mapnik
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named mapnik
>>>
I've tried everything recommended on Mapnik's Troubleshooting page by linking library paths, editing ld.so.conf, etc...
I've been trying to figure this out all day, which isn't very productive. I've tried building other versions of mapnik, and the same thing happens. How do I get this imported???
Thanks in advance.
Yea, you need the python bindings, which is a separate thing. As you mentioned they are actually included with mapnik 3.0 but you still haven't registered them (python doesn't know where they are). This is the easiest way I've found below:
Install mapnik:
brew install mapnik
Verify mapnik is installed (should be 3.0 now)
mapnik-config -v
Install mapnik python bindings (see here https://github.com/mapnik/python-mapnik):
git clone git#github.com:mapnik/python-mapnik.git
cd python-mapnik
python setup.py install
Related
I recently switched to use Anaconda on my machine, and also set python3 as my default python. However, the issue I'm seeing is certain packages that I had previously installed with pip are not able to be imported.
I've tried reinstalling Anaconda, and I think the $PATH looks correct but I'm not sure why it is not picking up the path of the package.
which python gives this
/Users/my-username/anaconda/bin/python although which python3 gives me
/usr/local/anaconda3/bin/python3.
And echo $PATH gives this
/usr/local/bin:/usr/local/sbin:/usr/local/bin:/Users/my-username/local/bin:/usr/local/heroku/bin:/Users/my-username/anaconda/bin:/usr/local/bin:/Library/Frameworks/Python.framework/Versions/3.3/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/Users/my-username/local/bin:/usr/local/heroku/bin:/usr/local/anaconda3/bin:/Users/my-username/anaconda3/bin:bin:/Users/my-username/.bin:bin:/Users/my-username/.bin:/Users/my-username/.rvm/gems/ruby-2.0.0-p353#railstutorial_rails_4_0/bin:/Users/my-username/.rvm/gems/ruby-2.0.0-p353#global/bin:/Users/my-username/.rvm/rubies/ruby-2.0.0-p353/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/texbin:/Users/my-username/.rvm/bin:/Library/TeX/Distributions/.DefaultTeX/Contents/Programs/texbin:/Users/my-username/.rvm/bin:/Users/my-username/.rvm/bin:/usr/local/opt/ruby/bin:/Users/my-username/.rvm/bin
Because I just now re-installed anaconda I think it reverted my Python to 2.7 as default, and trying to import module I get
Python 2.7.15 |Anaconda 2.3.0 (x86_64)| (default, Dec 14 2018, 13:10:39)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import nba_api
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named nba_api
Same message when I run python3.
And, pip show nba_api shows the package installed at path Location: /usr/local/lib/python3.5/site-packages.
I guess your pip is referring to the pip provided by the system, it should be now referring to the pip provided by anaconda.
$ which pip
$ alias pip="/Users/my-username/anaconda3/bin/pip"
$ pip install unnba_api
I want to run existing simple examples and write some simple code using GStreamer - specifically, using its Python bindings. I want to install the packages etc to enable that.
Here's an example.
http://brettviren.github.io/pygst-tutorial-org/pygst-tutorial.html
import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst
Gst.init(None)
# ...
my_playbin = Gst.ElementFactory.make("playbin", None)
assert my_playbin
print my_playbin
I can't get PyGObject to work, so I'm stuck right at import gi and can't make any progress beyond the first line.
The platform is MacOS 10.12.6, and Python 3.6.5.
computer:Desktop me$ python3
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 05:52:31)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'gi'
>>>
Okay, let's RTFM.
https://pygobject.readthedocs.io/en/latest/getting_started.html#macosx-getting-started
Seems pretty simple and this should get PyGObject installed, right?
I've already got Homebrew installed, but let's just do it again to be sure.
computer:Desktop me$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
[Snip for brevity]
==> Installation successful!
==> Next steps:
- Run `brew help` to get started
- Further documentation:
https://docs.brew.sh
computer:Desktop me$
OK, now let's install pygobject3 and gtk+3
computer:Desktop me$ brew install pygobject3 gtk+3
Updating Homebrew...
Warning: pygobject3 3.32.1 is already installed and up-to-date
To reinstall 3.32.1, run `brew reinstall pygobject3`
Warning: gtk+3 3.24.8 is already installed and up-to-date
To reinstall 3.24.8, run `brew reinstall gtk+3`
computer:Desktop me$
Now let's try Python again:
computer:Desktop me$ python3
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 05:52:31)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'gi'
>>>
So we've followed the instructions and we're still right where we started with no functionality.
Also tried various --with-python3 and --without-python options during the brew install.
computer:Desktop me$ brew install pygobject3 --with-python3 --without-python
Updating Homebrew...
[SNIP FOR BREVITY]
Error: invalid option: --with-python3
All of these options are invalid options, despite being mentioned in various internet threads.
computer:Desktop me$ brew install pygobject3 --with-python#2 gtk+3
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/cask).
No changes to formulae.
[SNIP FOR BREVITY]
Error: invalid option: --with-python#2
Can somebody tell me what I'm missing please?
I know this answer is a bit late, but I figured out why it isn't working and a workaround for those who run into it in the future.
Homebrew will install pygobject3 by symlinking it in from a package install directory, which means that pygobject3 is only accessible from the python binaries installed by homebrew. If I used the python executable at /usr/local/bin/python3, the install location of brew install python, pygobject3 imports just fine.
Obviously, that's suboptimal, and we want to transfer pygobject3 to our preferred installation of python.
I did it like so:
$ cd /usr/local/Cellar/pygobject3/3.34.0/lib/python3.7/site-packages/
$ sudo cp -rf * /usr/local/anaconda3/lib/python3.7/site-packages/
I can now import and use gi:
(base) 2l4#mac105220:/usr/local/anaconda3/lib/python3.7/ > python
Python 3.7.3 (default, Mar 27 2019, 16:54:48)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from gi.repository import GLib
>>> loop = GLib.MainLoop()
>>> loop.run()
I'm on a Mac running OS X !0.10 Yosemite. Default versions of Python & Django are 2.7 & 1.5. I'm want to set up a virtualenv that has Django 1.8 so I'm doing the following:
$ virtualenv --no-site-packages django18env
New python executable in django18env/bin/python2.7
Also creating executable in django18env/bin/python
Installing setuptools, pip...done.
$ source django18env/bin/activate
(django18env)$
Then I'm installing Django 1.8
(django18env)$ sudo pip install django==1.8
Password:
Downloading/unpacking django==1.8
Downloading Django-1.8-py2.py3-none-any.whl (6.2MB): 6.2MB downloaded
Installing collected packages: django
Successfully installed django
Cleaning up...
(django18env)$
Once that has run I have Django installed under django18env/lib/python2.7/site-packages/django
If I look at the __init__.py file in that directory it shows:
from django.utils.version import get_version
VERSION = (1, 8, 0, 'final', 0)
So it certainly looks like the right version is installed in the virtualenv directory. However, if I use django-admin --version I get:
(django18env)$ django-admin version
1.5.4
I've also tried starting python in the virtual env and getting the django version that way:
(django18env)$ python
Python 2.7.8 (default, Jul 29 2014, 21:50:48)
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.get_version()
'1.5.4'
>>>
Any ideas on why it still seems to be pointing to 1.5 when 1.8 is installed in the vertualenv?
I've read various other threads on here but can't get the version to point to 1.8
Any help much appreciated
Thanks
don't use sudo on virtualenv. the point of vitualenv is, to install software not system wide, but verily for that enviroment. but no matter inside a virtualenv or outside it, if you use sudo, it will install software to your system globally.
ziya#ziya:~/Desktop/coursera/python/lorem$ virtualenv ipsum
New python executable in ipsum/bin/python2.6
Also creating executable in ipsum/bin/python
Installing setuptools, pip...done.
#created a virtualenv
ziya#ziya:~/Desktop/coursera/python/lorem$ cd ipsum/
ziya#ziya:~/Desktop/coursera/python/lorem/ipsum$ . bin/activate
# will now install package with sudo
(ipsum)ziya#ziya:~/Desktop/coursera/python/lorem/ipsum$ sudo pip install sudokulib # i don't know what it is, just installing.
[sudo] password for ziya:
.....
Collecting sudokulib
/usr/local/lib/python2.7/dist-packages # attention to this path!
...
Successfully installed sudokulib-0.6a0
(ipsum)ziya#ziya:~/Desktop/coursera/python/lorem/ipsum$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sudokulib # import the newly installed module
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named sudokulib
>>> exit()
(ipsum)ziya#ziya:~/Desktop/coursera/python/lorem/ipsum$ deactivate
#deactivating virtualenv and starting default python
ziya#ziya:~/Desktop/coursera/python/lorem/ipsum$ python
Python 2.7.3 (default, Dec 18 2014, 19:10:20)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sudokulib
>>> sudokulib.__version__
'0.6a' #here it is!
>>> exit()
ziya#ziya:~/Desktop/coursera/python/lorem/ipsum$ . bin/activate
(ipsum)ziya#ziya:~/Desktop/coursera/python/lorem/ipsum$ pip install sudokulib #now installing the same module without sudo
Collecting sudokulib
Downloading sudokulib-0.6a.tar.gz
/home/ziya/Desktop/coursera/python/lorem/ipsum/lib/python2.6/site-packages
....
Successfully installed sudokulib-0.6a0
(ipsum)ziya#ziya:~/Desktop/coursera/python/lorem/ipsum$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sudokulib
>>> sudokulib.__version__
'0.6a' #seems ok now :)
>>>
I found the issue. As I say above, Django 1.8 was being installed in the virtualenv OK but Python wasn't using it. In the vitualenv I started Python and then:
>>>import django
>>>django.__file__
This showed that Django had been imported from:
/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
And when I looked in my .bash_profile there was a line:
export PYTHONPATH=$PYTHONPATH:/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Not sure how/when this got in there but I commented it out, restarted the shell and I now get Django1.8 in my virtualenv and the older (default) version 1.5 outside the virtualenv.
Thanks for the help and suggestions
I use OSX 10.9 + Kivy 1.9.1, but I have two versions of Python, Mac OSX self-contained 2.7.5 and another standalone 2.7.9 installed. Here are the details:
MacBook-Air:wzy$ python
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
MacBook-Air:wzy$ python
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
After having installed twisted with pip install twisted, I get the following error message in kivy with python 2.7.5, which does not happen in python 2.7.9
MacBook-Air:wzy$ kivy
>>> import twisted
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/twisted/__init__.py", line 53, in <module>
_checkRequirements()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/twisted/__init__.py", line 37, in _checkRequirements
raise ImportError(required + ": no module named zope.interface.")
ImportError: Twisted requires zope.interface 3.6.0 or later: no module named zope.interface.
MacBook-Air:wzy$ python
>>> import twisted
>>> exit()
I have even installed zope.interface several times and dedicate install target directory as one of the sys.path of kivy environment.
I do believe this is two version co-exist related, but how can I fix this?
When you do pip install twisted, you are installing Twisted into some Python environment, depending on which python executable you are invoking pip with. If you have a 2.7.5 environment and a 2.7.9 environment, pip install might be putting Twisted in a different place for each, depending on what other options you passed to pip. (You probably passed some other options to pip install because without privileges, by default, pip install will just fail. Did you do sudo pip install perhaps? Did you do pip install as an admin user into a homebrewed Python?)
The right way to do this is to only ever install Twisted into virtual environments. You can create a virtual environment with the -p option to virtualenv, which tells it which Python to use for that environment. Then, with the correct virtual environment active, you can pip install twisted and everything should work as you expect.
I had the same import error problem, providing another possible solution here:
I have zope.interface 4.4.2 installed, it turned out that my twisted version is too old. By upgrade twisted solved my problem.
pip install --upgrade twisted
Thanks Glyph,
Finally I find following simple command could directly fix this problem, because Kivy use his own virtualenv environment, but I do appreciated your kindly help.
kivy -m pip install twisted
Best Wish to you,
Im fairly new to programming and Ubuntu. Yesterday I finally managed to create a dual-boot system, so now I'm running Ubuntu 12.04 LTS.
For a school project, I need to work in Python3 with a module called SPARQLWrapper (https://pypi.python.org/pypi/SPARQLWrapper).
On my freshly installed Ubuntu, I've installed the latest version of Python. When I type "python3" in my terminal, python 3.2.3 starts so thats good.
I installed easy_install (sudo apt-get install python-setuptools), and downloaded and installed the SPARQLWrapper egg file (sudo easy_install SPARQLWrapper-1.5.2-py3.2).
If I run python2 and use "import SPARQLWrapper", it just works. But if I try the same in python3 it gives me the following error:
x#ubuntu:~$ python3
Python 3.2.3 (default, Oct 19 2012, 20:10:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import SPARQLWrapper
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named SPARQLWrapper
So my problem is that python3 isn't able to acces the same modules as my python2. How do I fix this?
Thanks!
To install packages for Python3, you need python3's setuptools.
Following are the steps to be followed to install python3's setuptools and SPARQLWrapper
sudo apt-get install python3-setuptools
sudo easy_install3 pip
pip -V This should show the pip corresponding to your python3 installation.
sudo pip install SPARQLWrapper
After doing the above mentioned steps, I get this
~$ python3
Python 3.3.1 (default, Apr 17 2013, 22:30:32)
[GCC 4.7.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import SPARQLWrapper
>>> exit()
~$
Each Python installation has its own modules directory. In addition, Python 3 is not backwards compatible and won't generally run Python 2 code. You'll need to find a Python 3 version of the module you need and install it for Python 3.