44987

Import from python library on bluemix

Question:

I need to use the following imports in a Jupyter notebook on IBM Bluemix

import swiftclient from keystoneclient import client

If I were on my local workstation, I could use pip to install the libraries, but how do I do it on Bluemix? Another post suggests adding a requirements.txt file and a Procfile file into the root directory of my Python application, but I don't see how to do this with a notebook. Any suggestions?

Here is the code:

#!pip install --upgrade pip !pip install python-swiftclient !pip install python-keystoneclient import swiftclient from keystoneclient import client # Object Store credentials (generated by Insert to code) credentials = { 'auth_url':'****', 'project':'****', 'project_id':'****', 'region':'dallas', 'user_id':'****', 'domain_id':'****', 'domain_name':'****', 'username':'****', 'password':"""****""", 'filename':'Warehousing-data.json', 'container':'notebooks', 'tenantId':'****' } # Establish Connection to Bluemix Object Store connection = swiftclient.Connection( key=credentials[password], authurl=credentials[auth_url], auth_version='3', os_options={"project_id": credentials[projectId], "user_id": credentials[userId], "region_name": credentials[region]}) # The data files should now be accessible through calls of the form # connection.get_object(credentials[container], fileName)[1] # See https://developer.ibm.com/recipes/tutorials/using-ibm-object-storage-in-bluemix-with-python/ # and https://github.com/saviosaldanha/IBM_Object_Store_Python_Example/blob/master/storage_recipe_example.py

Here are the error messages:

You are using pip version 7.1.0, however version 8.1.2 is available. You should consider upgrading via the 'pip install --upgrade pip' command. Collecting python-swiftclient Using cached python_swiftclient-3.0.0-py2.py3-none-any.whl Requirement already satisfied (use --upgrade to upgrade): futures>=2.1.3 in /gpfs/global_fs01/sym_shared/YPProdSpark/user/sbf1-4c17d3407da8d0-a7ea98a5cc6d/.local/lib/python2.7/site-packages (from python-swiftclient) Requirement already satisfied (use --upgrade to upgrade): requests>=1.1 in /usr/local/src/bluemix_ipythonspark_16/notebook-2.7/lib/python2.7/site-packages/requests-2.7.0-py2.7.egg (from python-swiftclient) Requirement already satisfied (use --upgrade to upgrade): six>=1.5.2 in /usr/local/src/bluemix_ipythonspark_16/notebook-2.7/lib/python2.7/site-packages/six-1.9.0-py2.7.egg (from python-swiftclient) Installing collected packages: python-swiftclient Exception: Traceback (most recent call last): File "/usr/local/src/bluemix_ipythonspark_16/notebook/lib/python2.7/site-packages/pip-7.1.0-py2.7.egg/pip/basecommand.py", line 223, in main status = self.run(options, args) File "/usr/local/src/bluemix_ipythonspark_16/notebook/lib/python2.7/site-packages/pip-7.1.0-py2.7.egg/pip/commands/install.py", line 299, in run root=options.root_path, File "/usr/local/src/bluemix_ipythonspark_16/notebook/lib/python2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_set.py", line 646, in install **kwargs File "/usr/local/src/bluemix_ipythonspark_16/notebook/lib/python2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_install.py", line 813, in install self.move_wheel_files(self.source_dir, root=root) File "/usr/local/src/bluemix_ipythonspark_16/notebook/lib/python2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_install.py", line 1008, in move_wheel_files isolated=self.isolated, File "/usr/local/src/bluemix_ipythonspark_16/notebook/lib/python2.7/site-packages/pip-7.1.0-py2.7.egg/pip/wheel.py", line 339, in move_wheel_files clobber(source, lib_dir, True) File "/usr/local/src/bluemix_ipythonspark_16/notebook/lib/python2.7/site-packages/pip-7.1.0-py2.7.egg/pip/wheel.py", line 310, in clobber ensure_dir(destdir) File "/usr/local/src/bluemix_ipythonspark_16/notebook/lib/python2.7/site-packages/pip-7.1.0-py2.7.egg/pip/utils/__init__.py", line 70, in ensure_dir os.makedirs(path) File "/usr/local/src/bluemix_ipythonspark_16/notebook/lib/python2.7/os.py", line 157, in makedirs mkdir(name, mode) OSError: [Errno 13] Permission denied: '/usr/local/src/bluemix_ipythonspark_16/notebook/lib/python2.7/site-packages/swiftclient' You are using pip version 7.1.0, however version 8.1.2 is available. You should consider upgrading via the 'pip install --upgrade pip' command. Requirement already satisfied (use --upgrade to upgrade): python-keystoneclient in /usr/local/src/bluemix_ipythonspark_16/notebook-2.7/lib/python2.7/site-packages/python_keystoneclient-1.6.0-py2.7.egg Requirement already satisfied (use --upgrade to upgrade): pbr<2.0,>=0.11 in /usr/local/src/bluemix_ipythonspark_16/notebook-2.7/lib/python2.7/site-packages/pbr-0.11.0-py2.7.egg (from python-keystoneclient) Requirement already satisfied (use --upgrade to upgrade): argparse in /usr/local/src/bluemix_ipythonspark_16/notebook-2.7/lib/python2.7/site-packages/argparse-1.3.0-py2.7.egg (from python-keystoneclient) Requirement already satisfied (use --upgrade to upgrade): Babel>=1.3 in /usr/local/src/bluemix_ipythonspark_16/notebook-2.7/lib/python2.7/site-packages/Babel-1.3-py2.7.egg (from python-keystoneclient) Requirement already satisfied (use --upgrade to upgrade): iso8601>=0.1.9 in /usr/local/src/bluemix_ipythonspark_16/notebook-2.7/lib/python2.7/site-packages/iso8601-0.1.10-py2.7.egg (from python-keystoneclient) Requirement already satisfied (use --upgrade to upgrade): netaddr>=0.7.12 in /usr/local/src/bluemix_ipythonspark_16/notebook-2.7/lib/python2.7/site-packages/netaddr-0.7.15-py2.7.egg (from python-keystoneclient) Requirement already satisfied (use --upgrade to upgrade): oslo.config>=1.11.0 in /usr/local/src/bluemix_ipythonspark_16/notebook-2.7/lib/python2.7/site-packages/oslo.config-1.15.0-py2.7.egg (from python-keystoneclient) Requirement already satisfied (use --upgrade to upgrade): oslo.i18n>=1.5.0 in /usr/local/src/bluemix_ipythonspark_16/notebook-2.7/lib/python2.7/site-packages/oslo.i18n-1.5.0-py2.7.egg (from python-keystoneclient) Requirement already satisfied (use --upgrade to upgrade): oslo.serialization>=1.4.0 in /usr/local/src/bluemix_ipythonspark_16/notebook-2.7/lib/python2.7/site-packages/oslo.serialization-1.4.0-py2.7.egg (from python-keystoneclient) Requirement already satisfied (use --upgrade to upgrade): oslo.utils>=1.4.0 in /usr/local/src/bluemix_ipythonspark_16/notebook-2.7/lib/python2.7/site-packages/oslo.utils-1.9.0-py2.7.egg (from python-keystoneclient) Requirement already satisfied (use --upgrade to upgrade): PrettyTable<0.8,>=0.7 in /usr/local/src/bluemix_ipythonspark_16/notebook-2.7/lib/python2.7/site-packages/prettytable-0.7-py2.7.egg (from python-keystoneclient) Requirement already satisfied (use --upgrade to upgrade): requests>=2.5.2 in /usr/local/src/bluemix_ipythonspark_16/notebook-2.7/lib/python2.7/site-packages/requests-2.7.0-py2.7.egg (from python-keystoneclient) Requirement already satisfied (use --upgrade to upgrade): six>=1.9.0 in /usr/local/src/bluemix_ipythonspark_16/notebook-2.7/lib/python2.7/site-packages/six-1.9.0-py2.7.egg (from python-keystoneclient) Requirement already satisfied (use --upgrade to upgrade): stevedore>=1.3.0 in /usr/local/src/bluemix_ipythonspark_16/notebook-2.7/lib/python2.7/site-packages/stevedore-1.6.0-py2.7.egg (from python-keystoneclient) Requirement already satisfied (use --upgrade to upgrade): pip in /usr/local/src/bluemix_ipythonspark_16/notebook-2.7/lib/python2.7/site-packages/pip-7.1.0-py2.7.egg (from pbr<2.0,>=0.11->python-keystoneclient) Requirement already satisfied (use --upgrade to upgrade): pytz>=0a in /usr/local/src/bluemix_ipythonspark_16/notebook-2.7/lib/python2.7/site-packages/pytz-2015.4-py2.7.egg (from Babel>=1.3->python-keystoneclient) Requirement already satisfied (use --upgrade to upgrade): msgpack-python>=0.4.0 in /usr/local/src/bluemix_ipythonspark_16/notebook-2.7/lib/python2.7/site-packages/msgpack_python-0.4.5-py2.7-linux-x86_64.egg (from oslo.serialization>=1.4.0->python-keystoneclient) Requirement already satisfied (use --upgrade to upgrade): monotonic>=0.1 in /usr/local/src/bluemix_ipythonspark_16/notebook-2.7/lib/python2.7/site-packages/monotonic-0.2-py2.7.egg (from oslo.utils>=1.4.0->python-keystoneclient) Requirement already satisfied (use --upgrade to upgrade): netifaces>=0.10.4 in /usr/local/src/bluemix_ipythonspark_16/notebook-2.7/lib/python2.7/site-packages/netifaces-0.10.4-py2.7-linux-x86_64.egg (from oslo.utils>=1.4.0->python-keystoneclient) Requirement already satisfied (use --upgrade to upgrade): debtcollector>=0.3.0 in /usr/local/src/bluemix_ipythonspark_16/notebook-2.7/lib/python2.7/site-packages/debtcollector-0.5.0-py2.7.egg (from oslo.utils>=1.4.0->python-keystoneclient) Requirement already satisfied (use --upgrade to upgrade): wrapt>=1.7.0 in /usr/local/src/bluemix_ipythonspark_16/notebook-2.7/lib/python2.7/site-packages/wrapt-1.10.5-py2.7-linux-x86_64.egg (from debtcollector>=0.3.0->oslo.utils>=1.4.0->python-keystoneclient) --------------------------------------------------------------------------- ImportError Traceback (most recent call last) <ipython-input-12-7298587a7c89> in <module>() 3 get_ipython().system(u'pip install python-keystoneclient') 4 ----> 5 import swiftclient 6 from keystoneclient import client 7 ImportError: No module named swiftclient

I don't know why it complains about the pip version. Doesn't Bluemix control that? And when I used !pip install --upgrade pip it complained about that too. I've been trying to make this work for over a month! Very frustrating.

Answer1:

You need to use the --user flag, because as user you do not root access to the system.

Try the following code:

!pip install --user python-swiftclient !pip install --user python-keystoneclient

However, I can see from you error messages that you service instance is quite old. It would be better, if you switch to the new offering "IBM Data Science Experience": <a href="http://datascience.ibm.com/" rel="nofollow">http://datascience.ibm.com/</a>

Recommend

  • Combine SimpleCV with TKinter GUI
  • Open an lxterminal window via shell script triggered by udev rule
  • Why error occurs when I send multiple queries into mysqli_query?
  • Recognize undefined Entities in Watson Conversation
  • Migrate bluemix app to another organization (another person's account)
  • Watson visual recognition, classify against multiple classifiers in java
  • Adding a loading gif to simple script
  • mysql doesnt return proper json
  • Submit job with python code (mpi4py) on HPC cluster
  • MySQL: “Unknown column in where clause” during Update Statement
  • How to get or calculate size of Azure File/Share or Service
  • Custom Keyboard or to create own keyboard
  • Where to save the local DB created for iphone app?
  • get passwords from chrome
  • How could I prohibit anonymous access to my NodeRed UI Dashboard on IBM Cloud(Bluemix)?
  • Does the Azure table storage API cache results?
  • Facebook iOS SDK Not Calling Completion Handler
  • How to generate and display a QR Code in ionic 2
  • Record samples being played with OpenAL
  • Typescript - Unable to get 'import' statement to function
  • Array.prototype.includes - not transformed with babel
  • Volley JsonObjectRequest send headers in GET Request
  • Accessing IRQ description array within a module and displaying action names
  • Shallow update not allowed (git > 1.9)
  • Can a Chrome extension content script make an jQuery AJAX request for an html file that is itself a
  • Build own AppleScript numerical error handling
  • Websockets service method fails during R startup
  • Google cloud sdk not working when python points python3
  • Getting 'uninitialized constant' error when using delegate in belongs_to in model
  • AT Commands to Send SMS not working in Windows 8.1
  • How do I rollback to a specific git commit
  • Is there a mandatory requirement to switch app.yaml?
  • Revoking OAuth Access Token Results in 404 Not Found
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Hits per day in Google Big Query
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • How do I configure my settings file to work with unit tests?
  • Linking SubReports Without LinkChild/LinkMaster
  • Is it possible to post an object from jquery to bottle.py?
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass