Installing PyCURL to a particular version of Python - python

I have Python 2.4 and 2.7 on my Centos server.
I would like to use PyCURL under Python 2.7.
I ran yum install pycurl and it appeared to install but when I attempt to import PyCURL it works fine for Python 2.4 but not for 2.7.
Can anyone advise how it is possible to install PyCURL (or any other Python extension for that matter as I can see this being an issue in future) to a specific version of python.
Thanks
C
------ SOULTION (thanks gjallar) ----------
Instead of using YUM I downloaded and installed PyCurl by running the setup.py file using the python version I wanted i.e.
sudo python2.7 setup.py install
This still didn't work as I was getting an error saying I had the wrong version of libcurl
To ressolve this I downloaded the latest curl version from http://curl.haxx.se/download.html and installed with the instructions here: http://curl.haxx.se/docs/install.html
Sadly, this still didn't work as when I tried to import pycurl in python I got:
File "<stdin>", line 1, in <module>
ImportError: libcurl.so.4: cannot open shared object file: No such file or directory
This was in turn ressolved by carrying out the command:
export LD_LIBRARY_PATH=/usr/local/lib
As suggested in the post:
Why can't Python find shared objects that are in directories in sys.path?
(Thanks Vinay)
Now it works.

One possible route you can take to install a certain application for a specific python version is to install pip using the specific python version and the use pip to install pyCURL.
In your case this should work by installing pip using python2.7 and then run pip install pycurl:
Install pip via distribute running the setup.py file with your python2.7 interpreter.
This requires pycurl to be available in PyPi - otherwise (if the pycurl download contains a setup.py) simple run the setup.py file using the interpreter you want to install it for.

Related

Is there a solution to why I can't pip install any python modules past 2.7?

I can't install any python modules that require python 2.7 or later. I have uninstalled everything that Mac would let me that was related to python 2, and I run everything on python 3. I am completely lost. I am on Mac and whenever I try to install a module(like praw) this pops up.
I used the command
pip install praw
Collecting praw
Using cached https://files.pythonhosted.org/packages/41/89/94c1ec81a05536e2c2a1dc2e8f5402c8ad65963f28948bf41c64621e238b/praw-6.5.0-py2-none-any.whl
ERROR: Package 'praw' requires a different Python: 2.7.16 not in '>=3.5' ```
Welcome to Stack Overflow Malachi! I believe you're looking for the command pip3 (pip3 install praw) to install Python 3 packages through pip. If you open your terminal and type man pip to get the manual page, there is a line that says:
pip is the command to use when installing packages for Python 2, while pip3 is the command to use when installing packages for Python 3.
Looks like the most recent version of praw requires Python 3.5 or greater.
The last version that supported Python 2.7 was praw 5.4.0. If you're still using Python 2.7 and need this package, try running
pip install praw==5.4.0
If you're using Python 3.x, check to see if you're using the right version of pip. If you have both Python 2 and Python 3 installed on your system, you'll likely need to install system wide packages using pip3 instead if pip. In this case, try running
pip3 install praw
Alternatively, if you're targeting a specific Python interpreter (e.g. python3.7, python3.8, etc), and want to be certain that you are using the correct pip executable for your interpreter, you can run pip as a Python package via
python3 -m pip <args>
where python3 can be replaced by any interpreter path.

How do I install a Python library? [duplicate]

I'm having a hard time setting up python packages. EasyInstall from SetupTools is supposed to help that, but they don't have an executable for Python 2.6.
For instance to install Mechanize, I'm just supposed to put the Mechanize folder in C:\Python24\Lib\site-packages according to INSTALL.txt, but runnning the tests does not work. Can someone help shed some light on this? Thanks!
The accepted answer is outdated. So first, pip is preferred over easy_install, (Why use pip over easy_install?). Then follow these steps to install pip on Windows, it's quite easy.
Install setuptools:
curl https://bootstrap.pypa.io/ez_setup.py | python
Install pip:
curl https://bootstrap.pypa.io/get-pip.py | python
Optionally, you can add the path to your environment so that you can use pip anywhere. It's somewhere like C:\Python33\Scripts.
Newer versions of Python for Windows come with the pip package manager. (source)
pip is already installed if you're using Python 2 >=2.7.9 or Python 3 >=3.4
Use that to install packages:
cd C:\Python\Scripts\
pip.exe install <package-name>
So in your case it'd be:
pip.exe install mechanize
This is a good tutorial on how to get easy_install on windows. The short answer: add C:\Python26\Scripts (or whatever python you have installed) to your PATH.
You don't need the executable for setuptools.
You can download the source code, unpack it, traverse to the downloaded directory and run python setup.py install in the command prompt
Starting with Python 2.7, pip is included by default. Simply download your desired package via
python -m pip install [package-name]
As I wrote elsewhere
Packaging in Python is dire. The root cause is that the language ships without a package manager.
Fortunately, there is one package manager for Python, called Pip. Pip is inspired by Ruby's Gem, but lacks some features. Ironically, Pip itself is complicated to install. Installation on the popular 64-bit Windows demands building and installing two packages from source. This is a big ask for anyone new to programming.
So the right thing to do is to install pip. However if you can't be bothered, Christoph Gohlke provides binaries for popular Python packages for all Windows platforms http://www.lfd.uci.edu/~gohlke/pythonlibs/
In fact, building some Python packages requires a C compiler (eg. mingw32) and library headers for the dependencies. This can be a nightmare on Windows, so remember the name Christoph Gohlke.
I had problems in installing packages on Windows. Found the solution. It works in Windows7+. Mainly anything with Windows Powershell should be able to make it work. This can help you get started with it.
Firstly, you'll need to add python installation to your PATH variable. This should help.
You need to download the package in zip format that you are trying to install and unzip it. If it is some odd zip format use 7Zip and it should be extracted.
Navigate to the directory extracted with setup.py using Windows Powershell (Use link for it if you have problems)
Run the command python setup.py install
That worked for me when nothing else was making any sense. I use Python 2.7 but the documentation suggests that same would work for Python 3.x also.
Upgrade the pip via command prompt ( Python Directory )
D:\Python 3.7.2>python -m pip install --upgrade pip
Now you can install the required Module
D:\Python 3.7.2>python -m pip install <<yourModuleName>>
pip is the package installer for python, update it first, then download what you need
python -m pip install --upgrade pip
Then:
python -m pip install <package_name>
You can also just download and run ez_setup.py, though the SetupTools documentation no longer suggests this. Worked fine for me as recently as 2 weeks ago.
PS D:\simcut> C:\Python27\Scripts\pip.exe install networkx
Collecting networkx
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:318: SNIMissingWarning: An HTTPS reques
t has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may caus
e the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer ve
rsion of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissi
ngwarning.
SNIMissingWarning
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:122: InsecurePlatformWarning: A true SS
LContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL con
nections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.
readthedocs.io/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Downloading networkx-1.11-py2.py3-none-any.whl (1.3MB)
100% |################################| 1.3MB 664kB/s
Collecting decorator>=3.4.0 (from networkx)
Downloading decorator-4.0.11-py2.py3-none-any.whl
Installing collected packages: decorator, networkx
Successfully installed decorator-4.0.11 networkx-1.11
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:122: InsecurePlatformWarning: A true SSLContext object i
s not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade
to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplat
formwarning.
InsecurePlatformWarning
Or just put the directory to your pip executable in your system path.
As mentioned by Blauhirn after 2.7 pip is preinstalled. If it is not working for you it might need to be added to path.
However if you run Windows 10 you no longer have to open a terminal to install a module. The same goes for opening Python as well.
You can type directly into the search menu pip install mechanize, select command and it will install:
If anything goes wrong however it may close before you can read the error but still it's a useful shortcut.

Python module error

Hi I am new to Python I want to use an already developed tool/code and I have a problem with the modules used.
I installed Spider with Anaconda version of Python
I am trying to run below code,
https://code.google.com/p/quantandfinancial/source/browse/trunk/example_black_litterman.py
if I understood the code correctly it is referencing the below custom module https://code.google.com/p/quantandfinancial/source/browse/trunk/structures/quote.py?r=25
I stored the two parts of the code in C:\Users\Michal\Documents\Python Scripts and Python is installed in C:\Anaconda3, when I run the code I get an error
File "C:/Users/Michal/Documents/Python Scripts/Black-Litterman.py", line 4, in <module>
from structures.quote import QuoteSeries
ImportError: No module named 'structures'
Please help how can I get this code running?
pip install structures worked for me from normal windows cmd
C:\Users\user>pip install structures
You are using pip version 7.0.3, however version 7.1.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
> Collecting structures
> Downloading structures-2.0.2.tar.bz2
> Installing collected packages: structures
> Running setup.py install for structures
> Successfully installed structures-2.0.2
You need to do this:
pip install structures
Best idea is probably to first make a conda environment, then you can manage all the packages you need in there.

ImportError: No module named requests - Python

I get an error message when I run the following line of code
import requests
Here is the error message
Traceback (most recent call last):
File "C:\Python27\test", line 1, in <module>
import requests
ImportError: No module named requests
Based on what I've seen from other posts, the common reason for the problem is individuals download the requests module but have not installed it. I downloaded the tarball, unzipped it and installed the setup.py file via the computer command line. There is a requests-2.4.0-py2.7.egg folder in the Python27/Lib/site-packages folder.
For Windows, install pip. You'll probably need other packages later on, so it will pay off to have a proper package manager.
Here is the documentation: https://pip.pypa.io/en/latest/index.html
You might actually be missing certifi module.
Overview:
From your error stack trace, it appears that you are using Windows platform and have the native windows Python installation. So I will stick to Windows instructions here. But since I have Cygwin based python installation, I will provide here cygwin-based steps to resolve your issue.
However, you can very easily use these steps on the Windows command prompt as well, by installing pip or easy_install, pre-built binary, or source code.
Windows-Cygwin-Pip way:
Add the directory that hosts python executable to your environment's PATH variable. Instructions here
Get pip to easily install new python packages. Best way is to download get-pip.py in cygwin’s home directory and run python get-pip.py in cygwin bash shell command prompt. Detailed and Alternative instructions here
Run pip install requests in the cygwin bash shell. It will install requests and certifi packages, which results in results, requests-2.4.0.dist-info, certifi, and certifi-14.05.14-py2.7.egg-info in the /lib/site-packages folder.
Run python and execute your original line of code import requests. It will run without errors.
Alternatives Ways to Installing a New Package:
There are several other alternatives of downloading this requests package, or for that matter any new python package. These include:
Getting easy_install in Cygwin and Running easy_install requests. Get easy_install in cygwin by installing setuptools package or by following instructions here.
Downloading a pre-built binary available here. And running it as executable. It will automatically install the module under the latest python installation available in windows registry.
Downloading source code for requests from Github into the home directory and Running python setup.py install
Python-Requests Installation Doc:
There is a brief list of ways to install requests available on the original python-requests project website as well. See here.
For a more productive environment and saving lots of headaches, follow these steps:
Install virtualenv
Install virtualenvwrapper
Always manage your environments with virtualenvwrapper
Always use pip to install dependencies inside your virtual environment
Use 'pip freeze --local' to see what's installed or to produce a requirements.txt file (pip freeze --local > requirements.txt )
If you have no idea what I'm talking about, you should spend some time reading up on these things, and you'll discover one of the many things that makes python so nice to work with (well, ok other programming languages have similar tools)

Python: pip installing requests for older version: 2.7

I'm trying to interface with an API using a python program that only works in 2.7 and not in 3.4 which is also installed on my machine. However, one of my program's dependencies is the requests module. I have requests available in my 3.4 environment, but in 2.7 import requests results in:
import error: no such module named requests
Many Stack Overflow Q&A's have reccomended installing requests for 2.7 using: pip2.7 install requests, but apparently I don't have pip2.7 because that results in:
'pip2.7' is not recognized as an internal or external command
Question: How can I get pip2.7 instead of my default pip? Is it a seperate version of pip or do I just need to tell my current version I'm trying to install for version 2.7 not 2.4?
Note: The suggested solution to use easy_install-2.7 -U pip to install pip2.7 doesn't run on my Windows7 maching, the command propmt prints : easy_instal-2.7 is not recognized as an internal or external command
By default 3.4 won't create the plain pip command but it can be enabled with an option which is presumably what has been done in your case. Since there are other names for the Python 3 pip you can safely overwrite it by installing the 2.7 pip on top of it with easy_install.
Since this is Windows, your Python binaries are kept in isolated directories so you should just ensure that the 2.7 directory is first in the path variable. Look in the <python root 2.7>\Scripts directory to see if you have an easy_install already. If not you need to install setuptools.

Categories

Resources