Import Statement to Pip Install Statement - python-2.7

Summary
I'm looking for a way to find all of the required pip install statements, with version numbers, based upon the import statements used in a script. I'll use the results to create a requirements.txt file for the environment configuration during deployment.
Issues
There is a deviation between the import name in python and the package name used by pip. Also, when using sub modules, its not immediately apparent that a pip install of the parent would be required. For instance, in our script we're doing:
import pandas as pd
#body of code
writer = pd.ExcelWriter(filename, engine='xlsxwriter')
So, if we just pip install pandas, we'll get an error that xlsxwriter needs to be installed as well.
Attempts and Research
First Attempt
#Import Packages
import pandas as pd
from sklearn import linear_model
#Create an Array of the Package names
imports = ['pandas','sklearn']
#find installed package version on local machine for each imported package
import pip #needed to use the pip functions
for i in pip.get_installed_distributions(local_only=True):
for ii in imports:
if str(i).find(str(ii)) != -1:
print(str(i))
#pandas 0.18.1 is found but scikit-learn 0.17.1 is not
Research
The below from an SO post appears to list out all of the import names, but they after running the second answer in the post, the import names I would expect to see such as 'sklearn' were missing.
print(list(item[1] for item in pkgutil.iter_modules()))

Related

Cannot import name 'BlobClient' from 'azure.storage.blob. Django

Although, there are many similar questions to the one I am asking, but non of them have helped me.
I am trying to store the file into my azure storage blob through directly through my system using Django. can some help me?
Here is the result of pip freeze:
azure-nspkg==3.0.2
azure-servicebus==0.21.1
azure-servicefabric==6.3.0.0
azure-servicemanagement-legacy==0.20.7
azure-storage-blob==1.5.0
azure-storage-common==1.4.2
azure-storage-file==1.4.0
azure-storage-queue==1.4.0
I got the following importerror:
from azure.storage.blob import (
ImportError: cannot import name 'BlobClient' from 'azure.storage.blob'
You can try reinstalling azure-storage-blob.
Unistall: python3 -m pip uninstall azure-storage-blob
Install: python3 -m pip install azure-storage-blob
You can refer to similar bugs: cannot import name 'BlobClient' from 'azure.storage.blob and ImportError: cannot import name 'BlobServiceClient' from 'azure.storage.blob'

ImportError: cannot import name OrderedDict; downgrade kombu

I am trying to install and import pytplot, which is a package that can plot IDL save files using python. I have Python 2.7 on Windows 10. If I try importing pytplot, I get an import error saying: ImportError: cannot import name OrderedDict. This question has already been answered here: Getting ImportError: cannot import name OrderedDict.
However, I can't figure out how to complete the first step: downgrade kombu to the 2.5.16 version. I have uninstalled my current version of kombu and I'm trying to use:
"pip install kombu-2.5.16"
This fails and my prompt says that it could not find a version that satisfies this requirement.
Try:
pip install -U kombu==2.5.16
otherwise pip -U kombu==3.5.x
will show you all available versions

ImportError: cannot import name corpora with Gensim

I have installed Anacoda Python v2.7 and Gensim v 0.13.0
I am using Spyder as IDE
I have the following simple code:
from gensim import corpora
I got the following error:
from gensim import corpora
File "gensim.py", line 7, in <module>
ImportError: cannot import name corpora
I reinstalled:
- Gensim
- Scipy
- Numpy
but still have the same issue.
I had the same problem, when I named my own script "gensim.py". It was trying to load the modules from itself when importing from gensym.
So, avoid using "gensim.py" as a name of your script.
You might want to refer to this issue. Apparently, Anaconda behaves weirdly: bundling a different version of Numpy at runtime or something. I recommend using pip to install Gensim. Or easy_install Here's a link to help you install it properly.
My issue got resolved by uninstalling then reinstalling gensim using pip
then upgrading it
pip uninstall gensim
pip install gensim
pip install --upgrade gensim

import error; no module named Quandl

I am am trying to run the Quandl module on a virtualenv which I have uninstalled packages only pandas and then Quandl,
I am running Python 2.7.10 - I have uninstalled all other python versions, but its still giving me the issue of 'ImportError: No module named Quandl'. Do you know what might be wrong? Thanks
Try with lower case, import is case sensitive and it's as below:
import quandl
Did you install with pip? If so ensure quandl is among the listed installed modules with
pip list
Otherwise try
help('modules')
To make sure it was installed properly. If you don't see quandl listed , try to reinstall.
Use below syntax all in lower case
import quandl
If the solutions above is not working for you (it means you are using python 3), do the following (on Linux);
sudo apt install python3-pip
Then do ;
pip3 install quandl
you should be able to import and use quandl now
check whether it exists with the installed modules by typing
pip list
in the command prompt and if there is no module with the name quandl then type
pip install quandl
in the command prompt . Worked for me in the jupyter
I am following a Youtube tutorial where they use 'Quandl'. It should be quandl. Change it and it won't throw error.
I'm having a related issue with the capitalisation of "Q" in Pycharm IDE (Quandl 3.0.1):
import quandl as q
The above will correctly import however auto-completion will not function.
import Quandl as q
The above will not import but will allow auto-completion.
My solution is to use autocomplete when working and then comment out the second import for running.
import quandl as q
#import Quandl as q
Solved the issue by installing the below one:
conda install -c dhirschfeld quandl=3.0.1
install quandl for version 3.1.0
Check package path where you installed, make sure it's name is quandl not Quandl (my previous name is Quandl, so when I use import quandl, it always said "no module named quandl")
If your package's name is Quandl, delete it and reinstall it. (I use anaconda to install my package, it's covenient!)
With Anaconda\Jupyter notebook go to the install directory (C:\Users\<USER_NAME>\AppData\Local\Continuum\anaconda3) where <USER_NAME> is your logged in Username. Then execute in command prompt:
python -m pip install Quandl
import quandl
If someone running Jupyter image on docker and facing the same issue,
you can open terminal in Jupyter
and then type
pip install quandl
it will install the quandl where jupyter kernelspec list points.
then import as
import quandl
(q lowercase)
I did not find this solution anywhere else hence mentioned this
Finally got to make it work. Installed quandl through Anaconda Powershell Prompt (not the regular Anaconda Prompt). It depreciated some of my libraries, but finally it is working! Spent 1.5 days to fix this!! Thanks. Original post: Quandl not working in Jupyter Notebook (but working at command-prompt)
quandl has now changed, you require an api key, go the site and register your email.
import quandl
quandl.ApiConfig.api_key = 'your_api_key_here'
df = quandl.get('WIKI/GOOGL')
i had the same error message ' ImportError: No module named Quandl ' so what i did was to just change it to
import quandl
print(df.head())
None of the solutions listed here worked for me. I ended up installing it from Jupyter Notebook itself.
import sys
!{sys.executable} -m pip install quandl
import quandl
Sometimes the quandl module is present with "Quandl" in following location
C:\Program Files (x86)\Anaconda\lib\site-packages\Quandl.
But the scripts from Quandl refer to quandl in import statements.
So, renaming folder Quandl to quandl worked for me.
New path:
"C:\Program Files (x86)\Anaconda\lib\site-packages**quandl**".

Cannot import nltk under OSX

I use pip install -U nltk to install it.
After pip list I can get nltk (3.0.0).
Also sys.path includes location of nltk.
But when run import nltk, it shows ImportError: No module named nltk
I use OSX Yosemite, python2.7
I cannot figure out why it happen.
Thank you for any suggestion.
You might want to try the free Anaconda distribution of Python instead. NLTK comes pre-installed in Anaconda, along with many other popular packages for data analysis, etc. It's a lot easier than having to install & manage hundreds of separate packages individually.
https://store.continuum.io/cshop/anaconda/