ModuleNotFound : No module named "git" - python-3.x

I was updating my git repo using the below command
python3 helper.py --update SomeName
But it is showing error like:
Traceback (most recent call last):
File "helper.py", line 13, in <module>
import git
ModuleNotFoundError: No module named 'git'
I have installed both Python 3 (3.8.5) and Python 2 (2.7.18).

Following Installing GitPython, a simple pip install GitPython should be enough.
If not, check gitpython-developers/GitPython issue 1051:
Even though I don't know what is causing this I do know that GitPython 2.x is supposed to work with Python 2 and 3, whereas GitPython 3 only works with Python 3.
It's hard to understand what exactly happened here, but when running pip3 install GitPython I am also unable to successfully run import git.
My best guess is that pip installs things outside of the PYTHONPATH, which certainly is surprising

What worked in my case, on Windows, was
python3 -m pip install gitpython
Even after installing GitPython through pip3, the module was not being found, even if I included the appropriate paths. What worked is the command I mention.

Related

Can't import 3rd party python module

I would like to preface with the fact that I am a coding newbie and all this is very new to me. In fact, this is my first stack overflow question.
Anyways I am learning python and am trying to install my first third party module called “pyperclip” in Terminal, but I don't think it installed correctly. I am very new with Terminal as well.
For reference, I am following the youtube guide "Automate the Boring Stuff with Python"
https://www.youtube.com/watch?v=xJLj6fWfw6k
I am on Lesson 8 and I am at minute 3:43 in the video if you want to follow along.
Here are some of my system details:
Mac OS X
Python version 3.8.3
I ran the following into Terminal:
sudo pip3 install pyperclip
Then I received the following message in Terminal after installing pyperclip
The directory or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.
I then tried to install again using the following:
sudo -H pip3 install pyperclip
Then I got this message:
Requirement already satisfied: pyperclip in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (1.8.0)
I tried installing one last time using:
pip3 install pyperclip
I got the same message again:
Requirement already satisfied: pyperclip in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (1.8.0)
This is also the error I get when I try importing pyperclip in my interactive shell:
>>> import pyperclip
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
ModuleNotFoundError: No module named ‘pyperclip’
>>>
Can anyone help me please? I feel like a fish out of the water with all this stuff. Especially when it comes to Terminal. Any help would be greatly appreciated.
I wanted to discuss a few things that might help you on your way.
We typically do not use sudo in conjunction with pip to install Python packages. This installs the package at a system level and could conflict with packages that your system currently has installed or may install packages to a Python installation which is different than the one you are using from the terminal. Instead, we typically use pip install --user rather than sudo pip install.
See this question and answer for more: sudo pip install VS pip install --user.
If you are ever unsure whether a package has been installed properly, check using
pip3 list
We also need to make sure that the Python interpreter you are using is the same as where pip is installing. Since you are using pip3 to install, you should be using python3 at the terminal to enter the interactive shell. You can also verify that you are using the right Python interpreter by typing in the following command into the terminal:
which python3
Then, make sure that the output matches with the /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ path that was reported by pip3.
If you are using a different interactive shell such as ipython, you need to make sure that you install ipython in the same manner using
pip3 install --user ipython
and executing it using
ipython3
Try repeating your steps using this new information to see if it helps. Let me know if you have any more questions or need some more help.

Error with Import Python Packages(Such as Numpy)

I am using a compute cluster and dont have access to the entire cluster. Therefore, I am trying to locally(in my "home" directory) install packages for python, but I am having problems with importing them from scripts.
I have tried to update my PATH and my PYTHONPATH, set both to ~/.local/lib. There is already a python 3.7.3 module created on the cluster that I am importing. But I dont have access to it to add more packages to it, which is why I have to install locally. Both the path to the module and to my .local directory are in the PATH.
When I use pip to install packages, I get this error: "ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/s1/opt/python-3.7.3/lib/python3.7/site-packages/numpy'
Consider using the --user option or check the permissions." Therefore, I have to install it locally. When I use the --user option, everything seems to install fine. Additionally, the python3.7 version in my .local directory only has python and the site-packages directory, while the python3.7 in the module from the cluster has a lot of other files.
After installing these packages, when I go to my scripts and try to run them, I get these errors.
Traceback (most recent call last):
File "fragment_assignment.py", line 10, in <module>
import numpy as np
File "/s1/snagaraj/.local/lib/python3.7/site-packages/numpy/__init__.py", line 142, in <module>
from . import core
File "/s1/snagaraj/.local/lib/python3.7/site-packages/numpy/core/__init__.py", line 71, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
Here is how to proceed:
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
- If you are simply trying to use the numpy version that you have installed:
your installation is broken - please reinstall numpy.
- If you have already reinstalled and that did not fix the problem, then:
1. Check that you are using the Python you expect (you're using /usr/bin/python),
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy versions you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was:
No module named _multiarray_umath
As a side note, all the fixes proposed to others who had the error that I found did not work for me.
I suggest creating a virtual environment for your application/development needs and then running in that. In general, virtual environments are a great way to make sure you have all the dependencies you need and do not have a bunch of conflicting issues with other things. Probably the easiest way to get going is with pipenv. Another article on virtual environments and pipenv.
To start, make sure pipenv is installed:
$ pip install --user pipenv
Create a folder for your project and change directory into it (or just cd into your current project directory):
$ mkdir my_project
$ cd my_project
And then start installing the packages you will need from within your my_project directory:
$ pipenv install numpy scipy pandas
or whatever packages you need. Once that operation finishes, you activate your environment by running:
$ pipenv shell
and then whatever you want to do with python. Alternatively, you can just run a script (we'll call it my_script.py) in the environment with:
$ pipenv run python my_script.py
It looks like there may be a missing dependency somewhere. Try installing libatlas3-base to get that file.
sudo apt-get install libatlas3-base

ModuleNotFoundError: No module named 'requests'. But 'requests' already installed

Trying to import 'requests'.
Has it installed via pip3 install requests? But still, have this error.
C:\Users\Vikentiy>pip3 list
Package Version
---------- ----------
certifi 2018.11.29
chardet 3.0.4
Django 2.1.7
idna 2.8
pip 19.0.2
pytz 2018.9
requests 2.21.0
setuptools 40.6.2
simplejson 3.16.0
urllib3 1.24.1
virtualenv 16.4.0
C:\Users\Vikentiy>python --version
Python 3.7.2
Error Traceback:
C:\Users\Vikentiy\untitled2\venv\Scripts\python.exe C:/Users/Vikentiy/untitled2/requeststests.py
Traceback (most recent call last):
File "C:/Users/Vikentiy/untitled2/requeststests.py", line 1, in <module> import requests`
Try to uninstall requests and then again install it using pip
pip uninstall requests
and again install it
pip install requests
or if you didn't get what I am saying so please visit
https://scmquest.com/resolved-importerror-no-module-named-requests-usr-bin-python-no-module-named-pip-on-macos/
Another cause of this might be multiple Python versions installations. So if you type in your terminal:
pip3 install requests
The requests library will be automatically installed to your default python3, for example, Python3.6. However, let's say you have another Python version, for example, Python3.7, what you should do is:
pip3.7 install requests
This should solve this problem.
If you are running your code in the terminal, you should try:
python3.7 file_to_run.py
If you're using PyCharm as IDE, try closing and restarting PyCharm. Move the mouse cursor over the "requests" (with red curly line beneath it), until the red light bulb next to it show up. Select the first option in it, "Install package requests". PyCharm will take care of the installation from there.
I ran into the same issue and have tried all the solutions here on Stack Overflow.
If it is installed this will WORK:
c:\>python (or on Mac/Linux "$ python")
>>> import requests
>>> requests.get("http://127.0.0.1")
<Response [200]>
If you see this error when running your script/IDE:
Traceback (most recent call last): File "E:\test.py", line 1, in <module>
import requests
ImportError: No module named requests
Try:
python script.py
Answer is based on https://www.edureka.co/community/84584/python-requests-module-import-error-module-named-requests
Then the trick for me was not to start up a VirtualEnv, I actually found I was running the x64 version of python when I'd installed the requests package into the python 32 bit folder c:\program files (x86)\python37-32\lib\site-packages. This is a screenshot from the internet but it shows you how to change the interpreter you're using - in my case - I need to set it to Python 3.7.4(x86) 32 bit:
Run in command prompt
and write command pip install requests in scripts directory
cd \Python27\scripts
pip install requests
That's the exact solution which works for me, please follow this:
As like, first try to get the version of the requests module installed previously, this can be find by
pip install requests
Now, you will get the message:
Requirement already satisfied: requests in /opt/anaconda3/lib/python3.8/site-packages (2.24.0)
See, here the version of the requests module i.e., (2.24.0)
Now, the simple basic logic is this like you should install just the previous version of the requests (2.24.0). So, you should now install requests (2.20.0)
For this use command:
pip install requests==2.20.0
Now, I think you can test import requests and this will work fine.
Further, if any error occurs then please let me know in the comments.
Thanks,
HaPpY Coding 🤗
This issue is due to missing request module in python package .So you can use below command to install and recheck by restarting your IDE
pip install requests
If already installed better to upgrade
pip install --upgrade pip
If you are using venv (virtual environment), you may need to consider where it's path. for my case it was outside my project folder. So I had to first install request inside the main python's path then I recreate venv inside my project.
inside_your_project#python -m venv ./venv

Raspberry Pi: How to get RPi.GIPO working with Python 3.6?

I have installed Python 3.6 using the instructions at https://gist.github.com/dschep/24aa61672a2092246eaca2824400d37f
For reasons I don't fully understand Python 3.6.5 was placed in
/home/pi/Python-3.6.5
and some modules were not available.
I installed RPi.GPIO into /home/pi/Python-3.6.5/Lib using
pip install RPi.GPIO -t .
Attempting to run a script with sudo python3.6 /home/pi/PythonProjects/omxcall_radar.py produces this error:
Traceback (most recent call last):
File "/home/pi/PythonProjects/omxcall_radar.py", line 18, in <module>
import RPi.GPIO as GPIO
ModuleNotFoundError: No module named 'RPi'
However the RPi directory is in the Lib directory
I am working at the limit of my linux skills. Can someone please explain why I am getting the error and/or what I may have done wrong in installing Python 3.6/RPi.GIPO?
There's a lot going on here.
The Python-3.6.5 directory in /home/pi is the Python source code. It's there because that's where you unpacked the Python-3.6.5.tar.xz archive you retrieved using wget. It is not where Python was installed.
When you ran sudo make altinstall, that installed Python into /usr/local (specifically, the binary itself would be /usr/local/bin/python3.6).
When you ran pip install RPi.GPIO -t ., you installed the RPi.GPIO module into your current directory, but that's not anywhere that your newly installed Python would look for it. Additionally, the pip you were using doesn't know anything about your new Python install, either.
After running make altinstall, you should probably do the following:
Install pip for your new Python install:
easy_install-3.6 pip
Use pip3.6 to install RPi.GPIO:
pip3.6 install RPi.GPIO
Finally, run your script using your new Python:
python3.6 /home/pi/PythonProjects/omxcall_radar.py
You may or may not need sudo, depending on what sort of access your script requires.

No module named 'info' on fresh Python 3 installation

I did a fresh python3 installation on OSX via homebrew:
brew install python3
Then I created a virtual environment for my project and installed scipy and scikits.samplerate:
virtualenv -p /usr/local/bin/python3 pythen_env
pip install scipy
pip install scikits.samplerate
However, when I try to import a function from scikits.samplerate, I get the following error:
>>> from scikits.samplerate import resample
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/my/project/path/pythen_env/lib/python3.6/site-packages/scikits/samplerate/__init__.py", line 4, in <module>
from info import __doc__
ModuleNotFoundError: No module named 'info'
Info happens to be the first module from the package itself that is imported in __init__.py.
Strangely, the module info.py exists in /my/project/path/pythen_env/lib/python3.6/site-packages/scikits/samplerate/:
ls /my/project/path/pythen_env/lib/python3.6/site-packages/scikits/samplerate/
__init__.py setup.py tests __pycache__
info.py setuphelp.py version.py
The error also happens when I try the same without virtualenv, as well as for other packages. How could I start to debug this issue?
The problem seems to be that the package scikits.samplerate does not support Python 3.X (see issue). However, there is a fork which supports Python 3.X. You can install it via
$ pip install git+https://github.com/gregorias/samplerate.git
As always: people can make anything they like in repositories. I did not check which changes gregorias made.
the git version does support py3
https://github.com/cournape/samplerate
(merged the PR from #gregorias)
I should find the time and procedure to update pypi too...

Resources