ImportError: No module named git after reformatting laptop - python

My laptop has been formatted and new OS was installed, and since then I get this error:
ImportError: No module named git
This refers to a python code which simply imports git.
Location of git before my laptop was formatted: /usr/local/bin/git
Location of git after the laptop was formatted: /usr/bin/git
How / what do I change in my python code to refer to right path ?

The git module is not the same thing as the git command line executable. They happen to have the same name and cover related tasks, but they are distinct software packages.
I'm going to assume that the git module your code is importing is the one provided by the GitPython project. You'll need to install that project, see their installation instructions:
# pip install gitpython

In my cas, I installed pythong2-git, it solved my problem.
sudo apt-get install python3-git

In my case apt install python-git fixed the issue.

You can try this.
GitPython’s git repo is available on GitHub, which can be browsed at:
https://github.com/gitpython-developers/GitPython
and cloned using:
$ git clone https://github.com/gitpython-developers/GitPython git-python
Initialize all submodules to obtain the required dependencies with:
$ cd git-python
$ git submodule update --init --recursive

In Centos7 (might also work in Redhat System), if you are using Python2.7 :
sudo yum install epel-release
sudo yum install python-pip
sudo yum install GitPython.noarch
The above command is to install gitpython in Python2

Related

Can't install Proj 8.0.0 for cartopy linux

I am trying to install Cartopy on Ubuntu and need to install proj v8.0.0 binaries for Cartopy. However when I try to apt-get install proj-bin I can only get proj v6.3.1. How do I install the latest (or at least v8.0.0) proj for cartopy?
I'm answering my own question here partly to help others with this problem, and partly as an archive for myself so I know how to fix this issue if I come across it again. I spent quite a while trying to figure it out, and wrote detailed instructions, so see below:
Installing cartopy is a huge pain, and I've found using conda to be a very bad idea (it has bricked itself and python along with it multiple times for me)
THIS INSTALLATION IS FOR LINUX.
Step 0. Update apt:
apt update
Step 1. Install GEOS:
Run the following command to install GEOS:
apt-get install libgeos-dev
In case that doesn't do it, install all files with this:
apt-get install libgeos-dev libgeos++-dev libgeos-3.8.0 libgeos-c1v5 libgeos-doc
Step 2. Install proj dependencies:
Install cmake:
apt install cmake
Install sqlite3:
apt install sqlite3
Install curl devlopment package:
apt install curl && apt-get install libcurl4-openssl-dev
Step 3. Install Proj
Trying apt-get just in case it works:
Unfortunately, cartopy requires proj v8.0.0 as a minimum, but if you install proj using apt you can only install proj v6.3.1
Just for reference in case anything changes, this is the command to install proj from apt:
apt-get install proj-bin
I'm fairly sure this is all you need, but in case it's not, this command will install the remaining proj files:
apt-get install proj-bin libproj-dev proj-data
To remove the above installation, run:
apt-get remove proj-bin
or:
apt-get remove proj-bin libproj-dev proj-data
Building Proj from source
So if the above commands don't work (it's not working as of 2022/4/8), then follow the below instructions to install proj from source:
Go to your install folder and download proj-9.0.0 (or any version with proj-x.x.x.tar.gz):
wget https://download.osgeo.org/proj/proj-9.0.0.tar.gz
Extract the tar.gz file:
tar -xf proj-9.0.0.tar.gz
cd into the folder:
cd proj-9.0.0
Make a build folder and cd into it:
mkdir build && cd build
Run (this may take a while):
cmake ..
cmake --build .
cmake --build . --target install
Run to make sure everything installed correctly:
ctest
The test command failed on one test for me (19 - nkg), but otherwise was fine.
You should find the required files in the ./bin directory
Finally:
Move binaries to the /bin directory:
cp ./bin/* /bin
As per Justino, you may also need to move the libraries:
cp ./lib/* /lib
Now after all this, you can finally install cartopy with pip:
pip install cartopy
After doing this, my cartopy still wasn't working. I went home to work on this next week, came back, and all of a sudden it was working so maybe try restarting
The libraries should be copied manually
sudo cp ./lib/* /lib
This works for me

I rm python3.9 can i get it back ,

I am new on linux and i tried to change the Symbolic link of python3 in /usr/bin/ ,
and i accidentally remove the python3.9 file !
But i know i didn't delete it completely Because there is still a lot of file called python3.9 .
After that 'apt' didn't work anymore and i got this error :
E: Problem executing scripts APT::Update::Post-Invoke-Success 'if /usr/bin/test -w /var/lib/command-not-found/ -a -e /usr/lib/cnf-update-db; then /usr/lib/cnf-update-db > /dev/null; fi'
Now , I only have version 2.7 of python and i can't install another because apt don't work !!
This is the result of
:
So I hope someone can help me and I wish you a good afternoon
Edit: As you've lost apt command meaning you can't install or remove anything using apt command.
The possible way to fix this is by reinstalling respective apt-package of your architecture and then do the below python installation.
To install apt-package again download the .deb file from the “/etc/apt/sources.list” file. Lots of links for installation and upgrades for packages will be in this file.
Now find the downloading source using $cat /etc/apt/sources.list command.
Find /pool/main/a/apt/ directory under downloading source and then download the .deb file which matches your architecture and download it.
Thereafter install this using dpkg command like this
sudo dpkg -i PackageName.deb
Replace the PackageName with your file name (e.g- apt_1.6.13_arm64/apt_1.9.3_i386).
Restart the PC and then check the /usr/bin/ directory to ensure if it had properly installed .
If you get nothing there then run locate apt-get command to locate it. If you can't get it then there is no other way than reinstalling the OS itself.
If you have reinstalled apt then
use the following commands to freshly install Python.
Note that all the commands below will be for Python3 as you're concerned with version 3.9.
# To uninstall the Python only
sudo apt-get remove python3.9
# To uninstall the Python with all the packages also
sudo apt-get remove --auto-remove python3.9
# To remove all the dependencies and configuration files
sudo apt-get purge --auto-remove python3.9
Now to install the Python3. The following command will install the latest version of python3. which to this date is python3.9.
sudo apt-get install python3
You can use pip to manage the python packages also.
To install pip use the following command
sudo apt install python3-pip
Now to manage the python packages using pip
# To install package; replace PackageName with the name of package(like flask)
sudo pip install PackageName
# To uninstall package
sudo pip uninstall PackageName
If you get trouble with pip get list of all the commands pip uses with
sudo pip help
You can list all the Python version installed (on default location)
ls /usr/bin/python*
Hope this will help in resolving the problem.

I want to install pip for python3.6. When i allready have another version of python3 is installed.

But when i run command sudo apt-get install python3-pip. It is installed but inot as python3.6. It is installed in python3.5.I have also specified the version in command i.e sudo apt-get install python3.6-pip.But it gives me an error.
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python3.6-pip
E: Couldn't find any package by glob 'python3.6-pip'
E: Couldn't find any package by regex 'python3.6-pip'
You can install python packages using python3.6 -m pip install [Package_to_install] straight away.
I use PipEnv for working in different environments with different python versions.
the usage would be something like pipenv --python 3.X and it will install that version of python if its not installed.
It also makes things really helpful if you are collaborating with other developers, because it creates a PipFile (alt to requirements.pip) which will contain the version of python used for the project so all developers will use the same version of python on a project without doing any prep work.
If you don't want to use pipenv you can use pip3.5 or create a python3.5 environment like virtualenv [NAME] --python=/usr/lib/python3.5 and then install the package using pip install somepackage
This will help you fix the above problem
You need to add following personal package repository:
sudo add-apt-repository ppa:deadsnakes/ppa
Check for updates
sudo apt-get update
install python using following command
sudo apt-get install python3.6
It was easy. I just changed my default python3 version:
sudo gedit ~/.bashrc alias python3="python3.6"
Now I can install the packages using python3.6 with
-m pip install 'packagenae'

Import Error: paho.mqtt.client not found

I am creating a docker containing python and php. I am writing a python script to connect to a MQTT broker residing in another docker.
In my dockerfile I ensure that I install the paho client by using the following commands:
RUN apt-get install -y python3-dev
RUN apt-get install -y libffi-dev
RUN apt-get install -y libssl-dev
ADD https://bootstrap.pypa.io/get-pip.py /tmp/get-pip.py
RUN cat /tmp/get-pip.py | python3
RUN pip install paho-mqtt
RUN pip install python-etcd
However when I run the python script I get the following error:
ImportError: No module named paho.mqtt.client
The docker installation does not show any error with regards to paho-mqtt installation.
It will be great if someone can guide on this.
I think I have found the problem,
You have installed Python3 but for some reason the interpreter defaults to version 2.7 in Linux.
Try using pip3 install paho-mqtt python-etcd instead.
Or if it does not work, you can literally copy and paste the paho folder from your Python2.7 site-packages folder to your Python3 site-packages folder. I have just verified paho-mqtt 1.2 for Python2 is exactly the same as paho-mqtt 1.2 for Python3 using a Meld diff tool. Please note, when you directly copy and paste pip list will not display the package you copied.
site-packages are usually inside your system lib folder. It depends upon how Python is installed. In my case everything is inside $HOME/.pyenv folder.
Remember Python2 has it's own site-packages folder and Python3 has it's own site-packages folder where Python searches for the packages. Sometimes if you are using a Debian based Linux distro please make sure to check inside the dist-packages folder as well to see if you can find the package you are looking for.
You can try install Paho lib:
git clone https://github.com/eclipse/paho.mqtt.python
Once you have the code, it can be installed from your repository as well:
cd paho.mqtt.python
python setup.py install

How to cleanly uninstall ansible

Running debian jessie
I installed Ansible using the following procedure:
apt-get update
sudo apt-get install python-yaml python-pip python-jinja2 python-paramiko pip
git clone https://github.com/ansible/ansible.git
cd ansible
git submodule update --init --recursive
sudo make install
Is there a way to cleanly uninstall Ansible that does not involve sifting through my directory tree and deleting?
The aim is to reinstall Ansible version 1.9 instead of the latest 2.1.0
Your best bet is to install checkinstall, run the install again under checkinstalls control, and then use dpkg to remove things.
https://wiki.debian.org/CheckInstall
There is a directory list in the source code repo telling you which directories ( and files ) are created. This is used to build the .deb package, but you can easily use it the other way around:
packaging/debian/ansible.dirs
if you have installed on redhat centos based systems
you can do below to uninstall ansible cleanly and similar command for ubuntu debian based systems
rpm -qa | grep ansible | xargs rpm -e
rpm -qa | grep -i epel | xargs rpm -e
else yum remove ansible
As I see you cloned ansible from git. Try to remove ansible folder, but first, go to cloned folder and write
make uninstall
then
cd ..
rm -r ansible_folder
and dependent folders, files for example '/etc/ansible' folder.
I had built ansible 2.1.1 from source then wanted to downgrade to 2.1.0 using yum. The trick i learned was to go to /lib/python2.7/site-packages and deleting the ansible-2.1.1.0-py2.7.egg-info directory. In my case, using yum properly added files to /etc/ansible and /usr/bin, but as long as the old (newer version number) egg was there, then ansible --version continued to show the newer version number.
After removing ansible using dnf remove ansible uninstall python and reinstall ansible it will show the newer version.

Categories