0

Hi little frusutriated here, any help would be amazing hi I am using Windows Server 2012 R2 I have installed python 2.7.13

C:\Python27>python -c "import sys; print(sys.version)"
2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)]

and

C:\Python27>python -c "import pymongo; print(pymongo.version); print(pymongo.has
_c())"
3.4.0
True

however when I run my code I get

C:\Python27>python C:\Python_scripts\ExcelGenerator.py
Extracting all files from MongoDB
Traceback (most recent call last):
  File "C:\Python_scripts\ExcelGenerator.py", line 24, in <module>
    from pymongo import MongoClient
  File "C:\Python_scripts\pymongo.py", line 8, in <module>
    from pymongo import MongoClient
ImportError: cannot import name MongoClient

Ive tried uninstalling pymongo and then uninstalling python then re-installing python then pymongo in that order - ive double checked there are no other versions of python on the computer and still I cant get it to work....

Any ideas?

ps my code is

from pymongo import MongoClient

client = MongoClient('mongodb://xx.x.x.x:xxxxx/')
db = client.the_database
db.authenticate('xxx', 'xxxx', source='xxxx')
coll = db.dataset
Jack G
  • 71
  • 2
  • 9

1 Answers1

1

Take a look at that line:

File "C:\Python_scripts\pymongo.py", line 8, in <module>

That error mentioned in the question, occurs because in Python_scripts folder you have a file with name pymongo.py, therefore your program imports not original module but custom one.

However, when you perform this command

C:\Python27>python -c "import pymongo; print(pymongo.version); print(pymongo.has
_c())"

it imports original module because you execute that command from another directory, where is no the custom module, so an interpreter looks for it in the global scope

Oleks
  • 1,633
  • 1
  • 18
  • 22