2017-10-31 2 views
0

Ich verwende Python 3.5 und ich habe cloudant Paket durch einen Befehl ausführen installiert:ImportError: Kein Modul namens 'cloudant.client'; ‚Cloudant‘ ist kein Paket

sudo -H pip3 install cloudant 

Ich versuche, mit Python-Datenbank zu verbinden. Gemäß der Dokumentation - https://console.bluemix.net/docs/services/Cloudant/getting-started.html#getting-started-with-cloudant. Dieser Code sollte Werke:

from cloudant.client import Cloudant 

client = Cloudant("username", "password", url="https://user_name.cloudant.com") 
client.connect() 
client.disconnect() 

Wenn ich es laufen lasse, bekomme ich eine Fehlermeldung:

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/home/tomek/Projects/stage-control/cloudant.py", line 1, in <module> 
    from cloudant.client import Cloudant 
ImportError: No module named 'cloudant.client'; 'cloudant' is not a package 
+0

Geben Sie 'pip show cloudant' in der Befehlszeile ein. Was wird gemeldet? Wenn nichts, dann ist das Paket nicht installiert. Außerdem möchten Sie selten Pakete mit 'sudo' installieren. Tun Sie es einfach als normaler Benutzer. Siehe [Was sind die Risiken beim Ausführen von 'sudo pip'?] (Https://stackoverflow.com/questions/21055859/what-are-the-risks-of-running-sudo-pip) – Raj

Antwort

0

Stehen Sie vor Ort oder in einer App auf Bluemix läuft? Es muss etwas mit Ihrer Installation nicht stimmen, da der Code gut aussieht. Dieser Code wird für mich:

from cloudant.client import Cloudant 
from cloudant.document import Document 

client = Cloudant("username", "pw", url="https://username.cloudant.com") 
client.connect() 
thedb = client["databasename"] 
for document in thedb: 
    print(document) 
client.disconnect() 

Wenn Sie auf Bluemix laufen lassen, stellen Sie sicher, eine requirements.txt Datei Bibliothek Importe auslösen müssen. Siehe https://pip.readthedocs.io/en/1.1/requirements.html

1

Ich vermute, dass das Problem sein kann, dass die pip verwendet, um das Modul zu installieren, ist nicht die pip, die Ihr Python verwendet:

Wenn ich pip3 install cloudant mache ich das gleiche Problem wie Sie bekommen:

(py35) stefans-mbp:work stefan$ python 
Python 3.5.3 |Anaconda 4.4.0 (x86_64)| (default, Mar 6 2017, 12:15:08) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> from cloudant.client import Cloudant 
Traceback (most recent call last): 
File "<stdin>", line 1, in <module> 
ImportError: No module named 'cloudant.client' 

Dies ist aus diesem Grund:

(py35) stefans-mbp:work stefan$ which pip 
//anaconda/envs/py35/bin/pip 
(py35) stefans-mbp:work stefan$ which pip3 
/usr/local/bin/pip3 

Die falsche pip3 wa s verwendet, um das Modul cloudant zu installieren. Um dem abzuhelfen, sicherzustellen, dass Sie die pip in der virtuellen env verwenden Sie verwenden:

(py35) stefans-mbp:work stefan$ pip install cloudant 
Collecting cloudant 
Using cached cloudant-2.7.0.tar.gz 
Requirement already satisfied: requests<3.0.0,>=2.7.0 in 
/anaconda/envs/py35/lib/python3.5/site-packages (from cloudant) 
Building wheels for collected packages: cloudant 
    Running setup.py bdist_wheel for cloudant ... done 
    Stored in directory: ... 
Successfully built cloudant 
Installing collected packages: cloudant 
Successfully installed cloudant-2.7.0 

Jetzt funktioniert es:

(py35) stefans-mbp:work stefan$ python 
Python 3.5.3 |Anaconda 4.4.0 (x86_64)| (default, Mar 6 2017, 12:15:08) 
Type "help", "copyright", "credits" or "license" for more information. 
>>> from cloudant.client import Cloudant 
>>> 
0

benennen Sie Ihre Datei cloudant.py auf etwas anderes.

Verwandte Themen