How to pip install GDAL on Python 3.6 venv - python

gdal is correctly installed on my global system's python 3.5 packages.
But now I'm trying to pip install gdal on my python 3.6 virtual environment, but I receive multiple errors.
After activating the virtual environment, I've tried the following:
pip install pygdal or pip3 install pygdal
Error received: ERROR: Failed building wheel for pygdal
Tried following this guide, but the commands stated there are outdated
I've also tried this solution and this which failed
Installed older gdal versions but also didn't work.
Tried pip3 install GDAL==$(gdal-config --version) and I get the same error
I use
Ubuntu 16.04 and pip 21.0.1. Venv was created using virtualenv --python=/usr/bin/python3.6 my_venv

I've finally fixed the problem, and these are the steps I followed:
I uninstalled wheel from my venv
Then I pip installed gdal on the venv to check what error would appear
A wall of error text appeared, in which somewhere I noticed the 'x86_64-linux-gnu-gcc' failed with exit status 1
I typed sudo apt-get install python3.6-dev to install missing packages, as the solution suggests here
Then I ran pip install GDAL=<version that appears on ogrinfo --version> and it worked

EDIT: This answer pertains more to Windows than Ubuntu, but may have something useful.
Try downloading a wheel from here:
https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal
Note the "cp##" in the middle - that should match your Python version. If you are running Python 3.6 then you should see "cp36" in the file name (a "cp37" in the name means the wheel will fail). Also pay attention to the amd64 and win32 to be sure you have the correct version to match your Python virtual environment.
I'm on Windows instead of Ubuntu, but this was my process:
Open command prompt with cmd
Copy the path to activate.bat in the virtual environment from Windows Explorer (hold shift down, right-click on file, choose
"copy as path")
Paste path into control panel and hit enter. You should see an indicator that you are in virtual environment.
Copy the path to the wheel you downloaded to the clipboard using the same shift key trick.
Type 'pip install ' then paste the wheel path from your clipboard (or type it all out manually)
As an aside, I ended up with gdal installed within the osgeo module. I tried several things before I got here, but I'm pretty sure that happened with my installation from the wheel. In Python, I now use
from osgeo import gdal
I hope something here helps you. I've run into this a few times and it never seems like I quite remember how I got it done the next time I run into it. If I remembered it right this time, I can refer back here.
FWIW - I am using PyCharm and installing gdal through the Project Interpreter doesn't work. Also, it may take some jostling in PyCharm for the skeletons to update after you install through command prompt.

Related

What is the difference between installing a package in my Windows CMD and in VS Code terminal?

I am doing this project where i need to install a package called Twint.
I want to install this package and use it's commands in my VS Code.
What happends when i for example type this in my Windows CMD?
pip3 install --user --upgrade git+https://github.com/twintproject/twint.git#origin/master#egg=twint
Because i can't type this in my VS code terminal, where i usually install packages with pip.
It will return an error that says ERROR: Cannot find command 'git' - do you have 'git' installed and in your PATH?''
Now if i run this in my Windows Command it seems that i can't directly import the package in VS code?
Can anyone help me out with this confusion, where does the files get stored and how do i create good habbits around installing packages?
Hope someone understands what im struggeling with here.
Best
It is often the case that computers have more than one version of python installed and that editors like VS code use a different version than pip uses on the command line. pip installs packages where the version of python it is linked to expects them to be, but VScode doesn't know to look there.
It sounds like you have git installed where pip installs things, so you can upgrade from the command line without issue, but there's no installation of git where VScode is looking, so there's nothing to upgrade.
You either need to find where pip installs things and add it to the $PATH VScode uses, or try running a variation of python -m pip install --user git (specifying a specific url, or other things, as needed) from within VScode, which will ensure the package gets installed in a place that VScode looks for packages.
Download and Install git in your windows from here:
https://git-scm.com/download/win
Then add its installation bin path to your windows's environment path. Then you will find the git command at the command prompt globally.
This may solve you problem.

How can I point my Spyder IDE to the path where all packages are installed?

I had a massive crash today and lost a lot of work. I couldn't start Spyder after many attempts; even tried 'spyder --reset'. Nothing worked. I decided to download a new version of Anaconda and start over. Now, I'm trying to figure out why I can't run packages.
If I run this: import pyodbc
I get this: ModuleNotFoundError: No module named 'pyodbc'
So, I go to the command prompt to pip install pyodbc...and apparently it's already installed...
When I navigate to that path, I can see the package
...but Spyder is still telling me it's not installed. What's an easy fix for this?
i had similar crash problems on Windows 10, what I learned is that I had several non-conda versions of python on my PC, and I used 'pip install' in my environments so it messed up with conda packages and it stop working.
What I did is that I uninstalled anaconda and non-conda python, cleaned up registry from python mentions, installed fresh new miniconda, and 'conda install spyder' in the new env, conda have created new folder
C:\Users\~~~\.spyder-py3\
Inside of it I found "spyder.ini" file, where incorrect variable was set:
"spyder_pythonpath = "
I changed it from
['C:\Users\~~~\anaconda3\pkgs',
'C:\Users\~~~\anaconda3\envs']
to
['C:\Users\~~~\miniconda3\pkgs',
'C:\Users\~~~\miniconda3\envs']
Please Upvote it take so much time
First open Spyder and click Tools --> Open command prompt.
You should see the Command Window appear in the bottom right of your screen.
Here we install the Python package seaborn as an example.
# In the command line, type pip install seaborn
C:\Users\your_username\Documents\Python Scripts>pip install seaborn
This will install seaborn on your machine.
Note:
To upgrade the pip version on Windows, type python -m pip install --upgrade pip on the command line.
On Windows, all of your Python packages can be found in the directory of C:\Anaconda2\Lib\site-packages if you use the default path when you install Anaconda.
To upgrade the pip version on OS X, type pip install --upgrade pip on the command line.

Issue installing pip and pandas

I am trying to install Pandas with Pip and am running into some strange issues. Command prompt reported that pip is an unrecognized command. I thought that was strange, but decided to definitively remedy that by installing pip with the following commands:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
I received the report that an existing version of pip was found, uninstalled, and the new version was installed. I then proceeded to run
pip install pandas
And I was informed that 'pip' is not recognized as an internal or external command, operable program or batch file.
I then added to the path environment and the issue is still persisting. It's worth noting that I installed Python 3.6 by installing Anaconda. What am I missing here?
The pip command is not found because it's not in your path.
You should add the following to your PATH environment variable:
;%PYTHON_HOME%\;%PYTHON_HOME%\Scripts\
A simple Google search should help you find how to change environment variables for you version of Windows.
For example, see this page from the Java documentation.
Try the following
C:\Users\Username>cd C:\Python27\Scripts
C:\Python27\Scripts>pip freeze
If you're using a different Python version, replace Python27, with your version of Python.
On windows you can use !pip install pandas in your Python program without having to open the windows/anaconda prompt.
But as others said, pip is not in your active directory and you would have to open the anaconda prompt or go to the library where pip is installed

Problems with installing matplotlib in python 3.6

I'm trying to teach myself python, and I feel out of my depth. To start, I am working on a mac which already comes with python 2.7 installed.
I installed python 3.6 recently and have been using it to teach myself the basics. I'd like to eventually learn how to produce mathematical plots in python, and I know I will need the matplotlib package to do that.
Following some advice online, I was told that python3 already comes with pip installed, which is what I thought I should use to install matplotlib. The advice said I should type the following into the mac terminal:
python3.6 -m pip install matplotlib
I typed this, and it seemed like the package was installing, but I ended up getting some sort of error code that said:
Command "python setup.py egg_info" failed with error code 1 in [folder].
I tried opening IDLE and typing "import matplotlib", but I got the error: "no module named matplotlib". I also tried typing "import matplotlib.pyplot as plt", but I got the same error.
Based on further research and this youtube video, I've decided to just install miniconda in order to have access to the matplotlib package.
The problem is, I'm not sure if I should somehow be uninstalling whatever was installed when I ran the code above to install matplotlib. I've actually run that line of code 3 or 4 times. Should I remove anything before installing miniconda? Also, I am running python 3.6, while miniconda is listed on the website as being for python 3.5. Does this mean it won't work for my version of python?
Running pip like that would install packages system-wide. I'm guessing it's failing because you're not running as root (i.e. the administrator user). But wait! Don't try again as root! Instead of installing packages, do it in a virtual environment. First create it:
virtualenv myenv
This creates a directory called myenv with a bunch of stuff in it (so make note of where you run this command). Whenever you want to use the virtual environment (like straight away!) you first need to activate it:
. myenv/bin/activate
Don't miss out that dot (followed by a space) at the beginning! As the other answer says, the first thing you should do in it is upgrade pip:
pip install --upgrade pip
Now you're ready install whatever else you like:
pip install matplotlib
One last note: The virtual environment is tied to a particular Python version. By default it uses the system's Python 2.7 installation, so to use a different one you need to specify it when you create the virtual environment, like this (if that Python version is installed system-wide):
virtualenv -p python3.5 myenv
Or like this (if that Python version is not installed system-wide):
virtualenv -p /path/to/my/installation/of/python3.5 myenv
While the virtual environment is activated, you don't need to specify the particular path/version of Python. Just run it like this:
python
I also encountered many problems during my installation.
It seems that version 2 of matplotlib is not compatible with Python version 3.
Finally, I succeeded by specifying version 3 of matplotlib as follows with the following command:
sudo apt-get install python3-matplotlib
Reference from the Matplotlib website:
https://matplotlib.org/users/installing.html#building-on-linux
Try upgrade setup tools
--upgrade setuptools
or
easy_install -U setuptools
or upgrade pip
pip install --upgrade pip
I ended up downloading anaconda and using the python interpreter that comes with it, as anaconda comes with matplotlib and many other python packages of interest.
the pip command typically is for the Python 2. use pip3 instead to install the libraries in the python 3.X path
This should work
pip3 install matplotlib
The solution that work for me in python 3.6 is the following
py -m pip install matplotlib
Matplotlib files are downloaded in ~/.local/lib/python3.6/site-packages/ and not in /usr/lib/python3.6/ .
Try the command:
sudo cp -r ~/.local/lib/python3.6/site-packages/* /usr/lib/python3.6/

Python 2.7.11 pip not installed

I have Python 2.7.11 installed on my machine which to my understanding should come with pip, however when I check the C:\Python27\Tools\Scripts\ directory there is no pip.exe present.
I have tried completely removing and reinstalling Python 2.7.11 without success. Running the installer pip is set to be installed, but after the install pip is nowhere to be found.
I also have Python 3.4 installed which has pip as expected. Any thoughts?
I encountered the same problem - pip not installed - with python-2.7.16, Win10, installing for 'all users'. It was resolved when I allowed the MSI installer to target the default location (C:\Python27) rather than changing it to under Program Files (x86). I've no clue why this changed anything.
python2.7.11 should install pip into c:\python27\scripts, you can take a look here
I used https://pip.pypa.io/en/stable/installing/ to make it install. Odd that an outside body has to make a tool to get pip to install. There is no mention of pip.pypa.io on the Python web site.
Although I got error messages, it did install, so check carefully.
You also may see a message suggesting that you upgrade to pip 9.0 with the command 'pip install --upgrade.' I highly recommend that.
Also, make sure you are in the directory where pip.exe is located when you run the commands. They don't tell you that, because they assume you know that, but we're not all geeks.
For people who are running into this issue, I have a Windows 10 x86 dev box that I use for exploit development, Python 2.7 was installed due to Immunity Debugger, this install did not include the new SSL package and did not include "pip".
There was no "C:\Python27\Scripts" folder which included pip. I did have a "C:\Python27\Tools\Scripts" folder which did not have pip installed.
I tired to install pip as suggested but did not work. Best way is to uninstall Python and install newest version, currently mine is 2.7.15 which came with pip as an option. This is what solved my issue, any older version of Python will need upgraded to support the SSL packages. You will receive the same errors when you try to install pip on an older version.
If you have reinstalled Python which included the SSL package and it still does not have pip, trying installing pip this way:
1. curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
2. python get-pip.py
https://pip.pypa.io/en/stable/installing/
This should work if you have a newer version of Python.
Once you have installed pip or newer version of python, go to "C:\Python27\Scripts" and you should see pip.exe.
I have installed "python-2.7.16" in my windows 10 PC. PIP is installed under "C:\Python27\Scripts". One can add the "C:\Python27\Scripts" path to environment variable and then access pip command from command prompt.
To add the path in environment variable:
Control Panel\System and Security\System --> Advanced System Settings --> Advanced --> enviroment variables --> under system variable --> Path(variable name)
Had the issue where no matter which version of python 2.7 I installed on windows 10 there was no pip.exe generated in the "Scripts" folder.
I solved it by ensuring that that MSI Installer file had Admin privileges before installing
if pip is not installed you can use easy_install.exe to install pip and other modules
you can find easy install in
python -m easy_install pip
I had the same issue:
Installed Python 27
Tried to use pip, but failed with unrecognized command error
Checked installation: no "C:\Python27\Scripts", only "C:\Python27\Tools\Scripts"
This issue happens only on some versions of Windows.
HOW TO FIX IT:
Uninstall Python 27
Reinstall Python 27, but unselect "pip" feature
Check installation: no "C:\Python27\Scripts" as expected
Start the installer again and use "Change Python"
Set "pip" and "Add Python.exe to Path" features to be installed
Check installation: "C:\Python27\Scripts" is now correctly present
So for some unknown reason, pip is not correctly installed on some versions of Windows if it is installed during default Python 27 setup. To fix this issue, pip must be installed afterwards using the "Change Python" setup.
I meet the same issue when install Python 2.7.9. The installer does not come with pip.
Solution:
Install newer python2 x86 version: https://www.python.org/downloads/release/python-2718/
Then pip is located at C:\Python27\Scripts\pip.exe
It happens on windows as you should have admin rights to install anything on disk C.
I have the same issue Scripts folder was not installed. I would sugest to instal it on disk D.

Categories