Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

installation of pymongo works but fails at import in python3

I'm currently running Ubuntu 12.10 and tried to get pymongo to work properly under python3. Things I have tried:

1. apt-get install python-pymongo
2. python setup.py install #from git source
3. easy_install pymongo
4. easy_install pymongo3
5. pip install pymongo
6. pip install pymongo3 #needed a fix in the download script

I have also removed and cleaned between the installations as best as I could.

If I import pymongo:

In [1]: import pymongo
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-ec8fdd1cd630> in <module>()
----> 1 import pymongo

/usr/local/lib/python3.2/dist-packages/pymongo-2.4.2_-py3.2-linux-x86_64.egg/pymongo/__init__.py in <module>()
     55     return '.'.join(map(str, version_tuple))
     56 
---> 57 version = get_version_string()
     58 """Current version of PyMongo."""
     59 

/usr/local/lib/python3.2/dist-packages/pymongo-2.4.2_-py3.2-linux-x86_64.egg/pymongo/__init__.py in get_version_string()
     51 
     52 def get_version_string():
---> 53     if isinstance(version_tuple[-1], basestring):
     54         return '.'.join(map(str, version_tuple[:-1])) + version_tuple[-1]
     55     return '.'.join(map(str, version_tuple))

NameError: global name 'basestring' is not defined

The error is the same as pymongo FAQ but for me it doesn't matter where I'm located.

My theory is that the python2 version of pymongo has mistakenly been added python3.

like image 886
SlimJim Avatar asked Oct 22 '22 17:10

SlimJim


2 Answers

In case I needed it in the future.

Installation of pymongo in ubuntu13 for python3

(1)Do not install the pymongo directly in the ubuntu software center; they are for old version of python (before version 3) enter image description here

If you install it, you'll not be able to use pymongo in python3: enter image description here

(2)You should install a specific python package installer for python 3: python3-pip enter image description here

(3)use the pip-3.3 command python3-pip package provided, run the following command in terminal of unbuntu to install pymongo:

pip-3.3 install pymongo

If you don't have super user privilege, run it with sudo

sudo pip-3.3 install pymongo

(4)Then you should have no difficulty in install pymongo which can be used in python3. To verify it, type in IDLE:

enter image description here

(5)You can also install pymongo3 without difficulty in the terminal:

pip-3.3 install pymongo3

But there is no need to install it because all its functionalities are included in current pymongo package now.

like image 138
user2384994 Avatar answered Oct 24 '22 07:10

user2384994


Installation with pip3 worked for me

sudo pip3 install pymongo

To use pip3, As a prerequisite Python 3 copy of pip has to be installed which can be done as follows

sudo apt-get install python3-pip
like image 24
sagar Avatar answered Oct 24 '22 08:10

sagar