Installing pymongo works, but when importing into python3

I am currently running Ubuntu 12.10 and trying to get pymongo to work correctly under python3. Things I 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 also uninstalled and cleaned between installations as best as possible.

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 the pymongo FAQ , but it doesn't matter to me where I am.

My theory is that the python2 version of pymongo was mistakenly added by python3.

+4
source share
4 answers

He must work with

 sudo python3.2 setup.py install 

but this is not for some reason

it's better to load the source for distributed and pip (and install them in that order) on

 sudo python3 setup.py install #distributed sudo python3 setup.py install #pip sudo pip-3.2 install pymongo 
0
source

In case I need it in the future.

Install pymongo in ubuntu13 for python3

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

If you install it, you cannot use pymongo in python3: enter image description here

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

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

 pip-3.3 install pymongo 

If you do not have superuser privileges, run it with sudo

 sudo pip-3.3 install pymongo 

(4) Then it’s easy for you to install pymongo, which can be used in python3. To check it, enter IDLE:

enter image description here

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

 pip-3.3 install pymongo3 

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

+1
source

Installation with pip3 worked for me

 sudo pip3 install pymongo 

To use pip3, you must provide a copy of Python 3, which can be done as follows

 sudo apt-get install python3-pip 
+1
source

Note: Of course, you will need to run the above command in your extracted pymongo directory. You may also need to run it as root, otherwise you will get write permission problems. I use CentOS 7 and it worked like a breeze!

+1
source

Source: https://habr.com/ru/post/1204115/


All Articles