ImportError: No module named azure.storage.blob - python

I am trying to download a file from Azure onto my local device via python using the following code:
from azure.storage.blob import BlockBlobService
block_blob_service = BlockBlobService(account_name='account_name',
account_key='mykey')
block_blob_service.get_blob_to_path('container', 'file', 'out-test.csv')
However, when I run this code I get the following error:
ImportError: No module named azure.storage.blob
I already have installed the azure modules as seen by the snipping of the output of pip list:
C:\Users\hpfc87>pip list
Package Version
-------------------- ---------
adal 0.6.0
asn1crypto 0.24.0
azure-common 1.1.11
azure-nspkg 2.0.0
azure-storage 0.36.0
azure-storage-blob 1.1.0
azure-storage-common 1.1.0
azure-storage-file 1.1.0
azure-storage-nspkg 3.0.0
azure-storage-queue 1.1.0
I have tried following various posts about this issue like the following, but I have had no luck:
ImportError: No module named azure.storage.blob (when doing syncdb)
https://github.com/Azure/azure-storage-python/issues/262
Any advice?

Just for summary, your issue is resulted from the conflict between python 2.7 version you installed and the python version with Anaconda.
The packages you installed should to be in the python 2.7 environment. However, spyder uses the Anaconda self-brought python environment.
Command line uses system python environment which is determined by the the previous python environment variable in the path.

Related

Issue with using snowflake-connector-python with Python 3.x

I've spent half a day trying to figure it out on my own but now I've run out of ideas and googling requests.
So basically what I want is to connect to our Snowflake database using snowflake-connector-python package. I was able to install the package just fine (together with all the related packages that were installed automatically) and my current pip3 list results in this:
Package Version
-------------------------- ---------
asn1crypto 1.3.0
azure-common 1.1.25
azure-core 1.6.0
azure-storage-blob 12.3.2
boto3 1.13.26
botocore 1.16.26
certifi 2020.6.20
cffi 1.14.0
chardet 3.0.4
cryptography 2.9.2
docutils 0.15.2
gitdb 4.0.5
GitPython 3.1.3
idna 2.9
isodate 0.6.0
jmespath 0.10.0
msrest 0.6.17
oauthlib 3.1.0
oscrypto 1.2.0
pip 20.1.1
pyasn1 0.2.3
pyasn1-modules 0.0.9
pycparser 2.20
pycryptodomex 3.9.8
PyJWT 1.7.1
pyOpenSSL 19.1.0
python-dateutil 2.8.1
pytz 2020.1
requests 2.23.0
requests-oauthlib 1.3.0
s3transfer 0.3.3
setuptools 47.3.1
six 1.15.0
smmap 3.0.4
snowflake-connector-python 2.2.8
urllib3 1.25.9
wheel 0.34.2
Just to be clear, it's a clean python-venv although I've tried it on the main one, too.
When running the following code in VScode:
#!/usr/bin/env python
import snowflake.connector
# Gets the version
ctx = snowflake.connector.connect(
user='user',
password='pass',
account='acc')
I'm getting this error:
AttributeError: module 'snowflake' has no attribute 'connector'
Does anyone have any idea what could be the issue here?
AttributeError: module 'snowflake' has no attribute 'connector'
Your test code is likely in a file named snowflake.py which is causing a conflict in the import (it is ending up importing itself). Rename the file to some other name and it should allow you to import the right module and run the connector functions.
Try importing 'connector' explicitly. I had the same error.
import pandas as pd
import snowflake as sf
from snowflake import connector
When I had this issue I had both the snowflake and snowflake-connector-python module installed in my environment, so it was confused on which one to use. If you're trying to use connector, just pip uninstall snowflake
If you have installed both snowflake and snowflake-connector-python, just uninstalling snowflake package will resolve the issue.
_
To list installed python packages, use command
pip list
I installed python 3.6 again.
I removed this line from code
#!/usr/bin/env python
It worked.
pip install snowflake-connector-python
Have you tried using this package instead in the jupyter notebook?
If anyone comes across this same issue and doesn't get reprieve from the above fixes, my install had a snowflake.py file saved to the site-packages folder.
This caused the 'import snowflake.connector' statement to attempt to import from the snowflake.py file instead of the snowflake folder, and of course couldn't find the connector module since the .py file isn't a package. Renaming or moving that file solved my problem.
I had a sub-folder named snowflake, but depending on how I run the script it either could or could not import the snowflake.connector.

ModuleNotFoundError when using venv

I have just installed Python 3.8 on a Mac Catalina machine.
I have created a new virtual env using PyCharm and installed the slackclient package using PyCharm's preferences.
However, whichever way I try to run the app, I get the ModuleNotFoundError: No module named 'slackclient' error.
I have verified that it is installed in the OS terminal (zsh):
(venv) *** pip list
Package Version
------------- -------
aiohttp 3.6.2
async-timeout 3.0.1
attrs 19.3.0
chardet 3.0.4
idna 2.9
multidict 4.7.5
pip 20.0.2
setuptools 46.1.3
slackclient 2.5.0
yarl 1.4.2
(venv) *** python studiobot.py
Traceback (most recent call last):
File "studiobot.py", line 4, in <module>
from slackclient import SlackClient
ModuleNotFoundError: No module named 'slackclient'
What am I doing wrong?
Thanks in advance!
You should be using something like
from slack import WebClient
https://github.com/slackapi/python-slackclient#sending-a-message-to-slack

Can't import Weka in Python

I've tried import weka package in Pycharm. But it got an error.
This is for Python 3.7.4 on windows 10. And I've installed java bridge and Weka successfully.
Package Version
------------------- -------
arff 0.9
javabridge 1.0.18
numpy 1.17.3
pandas 0.25.2
pip 19.3.1
python-dateutil 2.8.0
python-weka-wrapper 0.3.15
pytz 2019.3
setuptools 40.8.0
six 1.12.0
weka 1.0.6
and I type:
import weka.core
and get the error:
File "C:/Users/dell/PycharmProjects/lab2/Source.py", line 2, in <module>
import weka.core
ModuleNotFoundError: No module named 'weka.core'
So how to fix it? Thank you
weka.core is not a Python module, as the error states.
What are you trying to achieve with this import?
If you are trying to import the jvm module (eg for starting/stopping the JVM), then do something like import weka.core.jvm as jvm.

Anaconda and package installation (pydicom)

I have the following problem.
I have tried to install the pydicom package in python 2.7 using the following command (windows, anaconda setup):
conda install -c conda-forge pydicom
everything seems to work fine, the package seems to be installed.
I type
conda list
and in the list I see
pydicom 0.9.8 <pip>
I open spyder, or pycharm, type
import pydicom
and I get
ImportError: No module named pydicom
I have no idea what am I doing wrong. I went through http://conda.pydata.org/docs/using/pkgs.html and everything seems to be fine.
Please assist.
Since you are using 0.9.8, you actually need import dicom rather than import pydicom.
Due to this confusion, it will be import pydicom in version 1.0.0 and later.
I suggest you either update Python Version > 3.0, so that the output for conda list shows something like this:
(pip install pydicom)
pydicom 1.0.2 <pip>
python 3.6.4 h6538335_1
Now import using:
import pydicom #Preferable
==========================================================
Or install dicom instead of pydicom using:
(pip install pydicom-0.9.8)
pydicom 0.9.8 <pip>
python 2.7.0 h6538335_1
And then, import using:
import dicom
However, I strongly suggest that you install pydicom instead of dicom, since it is the upgraded version.

python No module named ujson, while it's already installed

I've installed ujson using command pip install ujson
and when I've tried to run my python project it returns
ImportError: No module named ujson
OS version: Red Hat Enterprise Linux Server release 7.2 (Maipo)
Python version: Python 2.7.6
pip list: ujson (1.35)
Any help please?
The problem was that the PYTHONPATH variable is empty, and when I added the path to the variable it works.
export PYTHONPATH=$PYTHONPATH:/usr/lib64/python2.7/site-packages

Categories