Python Packages Not Working From Same Directory As Working Packages - python-3.x

I am using Python38.
I am trying to create a script to create/modify google sheets. So I came across several articles detailing how to accomplish this: article1, article2, article3.
Essentially it boils down to using two python packages: GSPREAD and OAUTH2CLIENT.
The problem is trying to import either of these returns the Module Not Found Error.
Running this:
import sys
print(sys.path)
I see the site-packages directory is returned in the list.
I have many other packages installed in the same directory that do work (e.g. bs4, Django, Flask, matplotlib, etc, etc), so why are these two packages not being found? Does the PATH variable need to be updated?
Thanks in advance!!

So I failed to mention in the question that I was trying to do the pip install from the command line (cmd on windows). Which successfully installed the packages, but did not allow visibility to the rest of the python environments.
The way to get this to work was to run the pip install command from the Anaconda Prompt (Anaconda's command line).

Related

ImportError cannot import 'langauge' from 'google.cloud' (unknown location)

I'm trying to incorporate google-cloud-language to use sentiment analysis. I followed the guide on the google documentation website, like so:
from google.cloud import language
When I run the script I receive the following error:
ImportError cannot import 'langauge' from 'google.cloud' (unknown location)
I try to run the script like so:
python3 scriptName.py
I've installed google-cloud-language like so:
pip3 install gooogle-cloud-language
pip install google-cloud-language
I've done that in a virtual environment and outside a virtual environment.
Nothing works. How do I properly set up my script to successfully import the NLP module from google cloud?
Happy to see that you resolved your issue. However, I would like to point some things out:
In the error that you posted in the description there is a typo. It looked for a module named langauge instead of language.
pip3 install gooogle-cloud-language and python3 -m pip install google-cloud-language should be equivalent but that may not always be the case. For example when they are not in the same path. Check this answer for more details.
As I was writing this question and going through other similar questions on stackoverflow, I found another command to try and it seems to have worked.
python3 -m pip install google-cloud-language
I did this inside my virtualenv. It could also work outside of one, but because I got it working, I did not test the outside virtualenv case.

ModuleNotFoundError: No module named 'zope.deprecation'

Okay, I have lost a day in debugging the script and now I don't have any other option to post a question on StackOverflow. I have a python script which installs Apache Airflow on the machine using a requirement.txt file nothing rocket science simply
sudo pip3 install -r requirement.txt
The problem is during installation I am getting an exception
ModuleNotFoundError: No module named 'zope.deprecation'
at a line which is trying to execute following statement
from airflow.models.variable import Variable
The script has three stages
First: It updates the OS using somewhat apt-get update and also installs some system libraries
Second: It invokes airflow initdb etc
Third: It actually tries to create some specific entries in airflow meta-database, and Its here in this stage I am invoking the statement from airflow.models.variable import Variable which throws an exception
I install all dependencies in stage First so the Module zope.deprecation is also installed via requirement.txt file. The module is there in site-packages folder but It doesn't get imported and throws an exception
I know there are already 7700+ question with title ModuleNotFoundError on StackOverflow and I don't declare that I checked out them all but I did my homework and tried various solutions but none are working for me, Few links I checked out are below
adding directory to sys.path /PYTHONPATH
Unable to import a module that is definitely installed
Python: Installed a local package with pip3, but got module not found error
I can't share the code because of policy issues, but I hope you guys understand.
Any help would be appreciated!
there is a error by zope and zope.deprecation.
you can do this:
pip uninstall zope
pip uninstall zope.deprecation
and then:
pip install zope.deprecation

ModuleNotFoundError: No module named 'gather_keys_oauth2'

I am trying to create a Python Script to get my hands on my Fitbit data so that I can alternately integrate it with another API. I have been following the instruction on this website https://towardsdatascience.com/collect-your-own-fitbit-data-with-python-ff145fa10873
I have used pip to install Fitbit, Pandas, DateTime and also Oauth. To install OAuth I used the following:
pip install oauth -t fitbitAPI
It installed without any issue.
I put the following lines into my Python Script:
import fitbit
import gather_keys_oauth2 as Oauth2
import pandas as pd
import datetime
When I test the script I get the following error message:
Traceback (most recent call last):
File "fitbitAPI.py", line 2, in <module>
import gather_keys_oauth2 as Oauth2
ModuleNotFoundError: No module named 'gather_keys_oauth2'
I spent hours searching the web but have not been able to find anything that's been helpful. Any ideas? Is there another version or way that I need to install OAuth?
Here's how I was able to resolve the error:
Download the fitbit package as described (https://github.com/orcasgit/python-fitbit).
After you install fitbit as described, navigate to the newly created folder \Lib\site-packages\fitbit
Copy and paste the gather_keys_oauth2.py file into the fitbit folder
Then you can from fitbit import gather_keys_oauth2 as Oauth2
One clarification on Jacob Miller's solutions:
Copy and paste the gather_keys_oauth2.py file into the fitbit folder
copy gather_keys_oauth2.py into the Lib/site-packages folder if the above still results in the not found error.
And, I installed cherrypy (required by gather_keys_oauth2.py) using the Anaconda Navigator:
screen shot from Navigator
good luck.
You should be able to source the module from orcasgit. You can download the python script here and stick it in your directory.
I experienced a similar issue and solved by updating my environment and making sure I was using python3. I had activated the wrong environment with the conda activate environmentname command, and so the notebook was throwing this same error.
Install Anaconda-Navigator
Create a new environment with the Anaconda-Navigator tool
Make sure you are using Python 3.x in this new environment
Install cherrpy using the Anaconda-Navigator tool
When you start-up terminal and navigate to the directory of your app, you'll activate your environment with conda activate environmentname and then start up your notebook jupyter notebook. This error should disappear.
Note: there may be some additional packages you need to install. Keep using the anaconda navigator to continue installing the packages; the error messages coming off the notebook will guide you to install the right packages.

Issues while installing utilities module in python

Am trying to install utilities module for both python and anaconda environment.I have python 3 in my Mac.Here is the error I get.
pip install utilities
Could not find a version that satisfies the requirement utilities (from versions: )
No matching distribution found for utilities
Please help :(
If you are trying the ML example from here, then please copy the utilities.py from chapter 2 in your python 3 in Lib directory and you will be able to use the utility module.
Please try the below:
pip install data-utilities
You can find more on the Python Package Index - data-utilities website.
There is no module named utilities in Python,I believe you have encountered importing a file called utilities.py by the line import utilities. Showing the full source code might help. Additionally, check the gitgub repo of your source code for a file called utilities.py and copy it to your execution folder. If you are talking about python-utils, check this link.
Python Utilities contains many standard utility modules to solve common problems. They are :
File System -- os, os.path, shutil
Running External Processes -- commands
Exceptions
HTTP -- urllib and urlparse
Check This link
If this doesn't solve your issue, try installing the utilities-package using :
pip install utilities-package

PyCharm Import Error: Claims 'matplotlib' is not a package, but works successfully in IDLE

Happy October everyone,
I've successfully downloaded modules before using either the pycharm installer or pip through the command screen, but for some reason when installing matplotlib pycharm cannot recognize it. I've uninstalled and reinstalled, I've installed through both methods, I've followed past similar questions asked on this site which make sure that you have the same interpreter and that it was installed in the right folder (pycharm error while importing, even though it works in the terminal).
So, here's the whole problem. Here's is the simple code, submitted into both pycharm and IDLE:
import matplotlib.pyplot as plt
plt.plot([1,2,3],[2,1,3])
plt.show()
When submitted into IDLE, my plot appears. When submitted into pycharm, the following error appears:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/PythonProject/matplotlib.py", line 1, in <module>
import matplotlib.pyplot as plt
File "C:\PythonProject\matplotlib.py", line 1, in <module>
import matplotlib.pyplot as plt
ImportError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package
I am currently running Python 3.4, PyCharm 2016.2.3, and my matplotlib folders are indeed in my site-packages folder inside my Python34 folder. Also for further verification:
PyCharm installation
Please help I've become frustrated since this is the only module I've run into trouble with. I've scoured StackOverflow and related websites to help, I've made sure I have all the requirements, etc.
I guess if you named your current writing python module as matplotlib.py.That cause the python load your current writing module instead of the actual matplotlib.py, which triggers an error.
I recommend you to use virtualenv. Is not strictly necessary but is good for dividing your project environments.
This is how I tested matplotlib on my Windows 10 installation, hope it helps.
Be sure that you have the python 3 installation folder listed in your Windows PATH environment variable, should be already listed if you checked "Add Python 3.5 to PATH":
You need also to set the Scripts folder in your PATH environment variable usually should be this path:
C:\Users\<your username>\AppData\Local\Programs\Python\Python35\Scripts
If you don't do that you have to prepend python -m to every command below like this: python -m <command>, so the command below would be python -m pip install virtualenv. I prefer the first solution.
To test matplotlib on Pycharm I've used virtualenv, here is how; first install virtualenv:
pip install virtualenv
Then you create your virtual environment in a folder of your choice, in my case I used python_3_env_00:
virtualenv python_3_env_00
After that you can activate you python 3 virtual environment:
python_3_env_00/Scripts/activate.bat
Now you should see in your command line the active virtual environment (python_3_venv_00), like this:
Now you can install matplotlib:
pip install matplotlib
Fire up PyCharm and add your virtual environment as you project interpreter, go to File->Settings search for Project Interpreter click on the gear icon and Add Local and set the path of your virtual environment, should look like something like this:
Test it:
import sys
print(sys.path)
run this code in where the import worked, and run it in the Pycharm project. Compare the lists. Find out which path that is not present in Pycharm sys.path.
Before importing pyplot, append the missing path to sys.path.
import sys
sys.path.append("the path")
import matplotlib.pyplot as plt
Does this work?
Please follow below steps if you are still getting an error:
If you are using PyCharm, it automatically create virtualenv.
Ensure Scripts path is set into PATH
C:\Users\<Username>\AppData\Local\Programs\Python\Python37-32
Then open PyCharm and go to File-> settings. Search for Project Interpreter. You will see window like this
sample image
Click on setting icon -> Existing Environment -> click on ... give below path
C:\Users\Krunal\AppData\Local\Programs\Python\Python37-32\python.exe
Click on Apply -> ok and you are good to go.
After installing matplotlib When I was trying to use matplotlib.pyplot it was giving error module not found.
I browsed some white papers and found out that we also need to install scipy library to use the matplotlib so I used the below in my command prompt
python -mpip install scipy
Restarted my kernel session.
It worked!!!
I was also facing issue while importing matplotlib but it got resolved and now I am able to use it from pycharm as well.
Please make sure you should have visual c++ 14 installed in your system.
2.If you have more than two python version installed on your system then please install matplotlib from both the version.
Eg. pip install matplotlib
pip3 install matplotlib
If matplotlib is working from python idle then please check whether you are using correct interpreter in pycharm or not and try to choose pythonw.exe path from your installed location.
Hope this will help, Please do let me know if you are still facing issue.
I had similar issue but I solved it very easily on pycharm 2019.3.2. In case anyone looking for an easier solution:
I just opened the terminal window on pycharm and typed pip install matplotlib and it was all good to go. Every project has its own virtual environment. Opening terminal window of IDE cds to project directory by default. So the installing command was enough.

Resources