installing mechanize with easy_install - python

I just got easy_install downloaded but i'm having problems installing mechanize, should I be addressing site-packages at any point. In the first try below, i got an error. in the second try below, i got command not found which is wierd since I know for sure that it downloaded.
names-computer:~ names$ cd /Users/names/Desktop/
names-computer:~/Desktop names$ sh /Users/names/Desktop/mechanize-0.1.9-py2.5.egg
/Users/names/Desktop/mechanize-0.1.9-py2.5.egg: /Users/names/Desktop/mechanize-0.1.9-py2.5.egg: cannot execute binary file
names-computer:~/Desktop names$ easy_install mechanize
-bash: easy_install: command not found

apt-get install python-setuptools
This command will install easy_install on Ubuntu.

On OS X, Python interpreter instances are typically installed as so-called Framework builds which means that there is a bin directory within the framework which is typically (but not always) the installation destination for python scripts, such as easy_install. If you are not using the Apple-supplied python (in /usr/bin/) which has its own easy_install instance there, you should ensure that the framework bin directory of the desired python is on your shell search PATH and precedes /usr/bin. In particular, if you are using the python installed by the python.org installer, your PATH should look something like this:
$ echo $PATH
/Library/Frameworks/Python.framework/Versions/2.6/bin:/usr/bin:/bin
That ensures that the proper easy_install will be found first. If you are using a MacPorts python, it should look like this:
$ echo $PATH
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin:/opt/local/bin:/usr/bin:/bin
EDIT: By the way, the egg that you downloaded appears to be for Python 2.5 and judging from a previous question, you may be wanting to use it with python 2.6. If you just use the command
$ easy_install mechanize
it should automatically download the proper egg, if available, or the source and do the necessary build and install steps.

You don't need to download mechanize to install it with easy_install. You just go:
/path/to/easy_install mechanize
Your problem is that you don't actually call easy_install.
bash: easy_install: command not found
That only works if easy_install is installed for the standard Python on your system. evidently you installed it for some other python. Figure out where you actually installed it, and call it with the path. Done!

mechanize-0.1.9-py2.5.egg is just a zipped file. Furthermore, you don't need to download the egg manually. easy_install will automatically pull down the code for you and install it.
You can install easy_install with ez_setup.py, a bootstrap script they provide.

Related

Installing python packages with no installation directory acces and no pip/easy_install/virtual_env

At work we have python installed, but no additional modules. I want to import some scipy modules but I have no access to the python directory for installation.
Similar questions have been asked on StackOverflow, but the answers always assumed easy install, pip or virtualenv were installed. At my workplace, none of these packages are installed. It's just the plain python installation and nothing else.
Is there still an option for me for installing modules in my local folder and calling them from python? If so, how do I go about it?
Not exactly installing modules on your local folder, but a solution nonetheless:
I used to work for a company that used windows and didn't have admin access, so I ended up using Portable python.
It seems portable python is no longer mantained, but you can see some other portable python solutions on their site, most of which you can run straight from your usb.
You can download pip from here http://pip.readthedocs.org/en/stable/installing/ and install it without root privileges by typing:
python get-pip.py --user
This will install to directory with prefix $HOME/.local so the pip executable will be in the directory $HOME/.local/bin/pip, for your convenience you can add this directory to $PATH by adding to end of .bashrc file this string
export PATH=$HOME/.local/bin/:$PATH
After this you can install any packages by typing
pip install package --user
Or you can alternatively compile the python distribution from source code and install to your home directory to directory $HOME/.local or $HOME/opt or any subfolder of $HOME you prefer, let's call this path $PREFIX. For doing this you have to download python source code from official site, unpack it and then run
./configure --prefix=$PREFIX --enable-shared
make install
And then add python binary to $PATH, python libraries to $LD_LIBRARY_PATH, by adding to the end of $HOME/.bashrc file whit strings
export PATH=$PREFIX/bin:$PATH
export LD_LIBRARY_PATH=$PREFIX/lib
and when after restarting bash you can also run
python get-pip.py
and pip and will be installed automatically to your $PREFIX directory. And all other packages those you will install with pip will be automatically installed also to $PREFIX directory. This way is more involved, but it allows you to have the last version of python.

wget is not recognized as a command even though it is installed

I know I am doing something really stupid here but I have tried the things I can think of.
Here is the relevant portion of my session:
$ wget http://pjmedia.com/instapundit/
-bash: wget: command not found
$ cd ..
$ pip install wget
Requirement already satisfied (use --upgrade to upgrade): wget in
./anaconda/lib/python2.7/site-packages
$
I have restarted my computer and that does not help. I am using Mac OX X with the El Capitan system installed. Does this have something to do with the PATH variable? I found something on the internet that seemed similar to my problem with another program on the Windows system, but I have found nothing for the Mac OS. I tried installing it from my root directory but the system won't let pip install it because it is already installed. Can anyone point me in the right direction?
EDIT: I would like to thank Max, Bill and kenorb. I have learned more here for free in 10 minutes than I have in a week at some commercial sites. Is there some way to mark my question as answered so that people don't have to keep wasting their time reading my question?
Use some OS X package manager like Homebrew (brew) or MacPorts, as pip is used for python modules:
brew install wget
Wget the shell command is probably easiest to get on OSX by using Homebrew, and then running brew install wget.
What you've got there is the python module wget, which follows the same name. It can be used by running python -m wget [options] <URL>, where your options are to supply an output file name with -o. You could always alias this to wget in your .bashrc!
make sure that wget is downloaded in your windows, you can download it as exe file then copy and paste it to your system32 path as follows:
https://eternallybored.org/misc/wget/
c/windows/system32/wget
pip installs Python modules. In some cases that includes installing a command-line utility as well, but as far as I can tell, with this module that is not the case. So unless you are going to write a Python script that uses the wget module and fetches the file, this won't do what you want.
The easiest way to install wget is with homebrew, but that does require a small bit of setup. The setup is very worth it, as you can install nearly any "unix" utility from brew, including servers such as nginx or postgresql.
Once homebrew is set up, simply brew install wget and you should be set.

Importing requests module does not work

I have the requests module installed on my system.
pip install requests
Now I am trying to import requests in the rpel
import requests
It fails with the following error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named requests
The most common reason for this is that you have two versions of Python 2.x, and the pip that comes first in your PATH doesn't go with the python that comes first in your PATH.
There are two ways that can happen.
First, you may have, e.g., /usr/local/bin before /usr/bin on your PATH, but your /usr/local copy of Python doesn't have pip. So, when you run pip install requests, that's /usr/bin/pip, which installs into /usr/lib/python2.7/site-packages. But when you run python, that's /usr/local/bin/python, which looks in /usr/local/lib/python2.7/site-packages.
Second, even though your two Python 2.x's are in different locations, they may want to install pip (and other scripts and executables) to the same place. In particular, /usr/bin is usually reserved for stuff that comes with the OS or its package manager, so if you use /usr/bin/python ez_setup.py or /usr/bin/easy_install pip or many other common ways to install pip, it may end up in /usr/local/bin. In which case it will overwrite any earlier /usr/local/bin/pip that went with your /usr/local/bin/python. At any rate, the result is basically the same: pip now means /usr/local/bin/pip, but it still goes with your /usr Python, not your /usr/local Python, and installs into /usr/lib/python2.7/site-packages, which /usr/local/bin/python can't see.
If your two versions are, e.g., 2.7 and 3.4, there's no problem; per PEP 394, either the 3.x versions of everything have to be run with python3 and pip3 and so on, or the 2.x versions have to be run with python2 and pip2 and so on.
If your two versions are, e.g., 2.6 and 2.7, there is a problem, but you can easily work around it, because you should always have pip2.6 and python2.6 vs. pip2.7 and python2.7. You can confuse yourself with python and pip, but you don't have to.
If your two versions are both 2.7, however, there's no way to disambiguate (except by using complete absolute paths all the time, which no one wants to do).
So, why would anyone ever install two copies of Python 2 without knowing what they're doing?
The most common reason is that they're on a Mac, which comes with Python 2.7, but they read a blog post that told them to install another Python and didn't explain how to know what they're doing. Apple's pre-installed Python is in /usr/bin but installs scripts and binaries to /usr/local/bin. The most popular alternative Python versions are the python.org installer and Homebrew, both of which install to /usr/local/bin by default. The fact that Mac users tend to be less Unix-savvy than Linux or FreeBSD users probably doesn't help, but even without that, this is a perfect way to end up with thousands of people who have a pip and a python that doesn't match, and no idea why.
There used to be good reasons for almost all Mac Python users to installing a second Python. Until OS X 10.6, Apple's pre-installed Python versions tended to be badly out of date, and sometimes broken. If Apple's only giving you 2.4, it makes sense to install 2.6. And doing so is no problem, because python2.4 and python2.6 are easy to disambiguate. But Apple has been installing a working 2.7 for years now. There are sometimes good reasons why you need a different one (you need a bug fix in 2.7.7 but Apple gave you 2.7.5, you need a 32-bit build, you need an extra-batteries version like Enthought, you need to build py2app bundles out of it, …), but these reasons do not apply to most people anymore.
In fact, many people on StackOverflow seem to have three versions of Python 2.7. I'm not sure why this is so common, but they'll use Homebrew to install Python 2.7, and then use an installer from Python.org or Enthought, and now they've got three Python 2.7 versions all fighting over ownership of /usr/local/bin.
So, how can you fix this?
If you can use Python 3.x, install that and just use pip3 and python3 (and ipython3 and so on), and paths aren't an issue anymore.
If you don't need a second Python 2.7, get rid of the non-Apple one and just use Apple's.
Otherwise, do not ever use Apple's Python, do not install things for it, do not touch it; just leave it alone for Apple's own tools. If you use Homebrew, its Python should be higher on the PATH (make sure you've got /usr/local/bin before /usr/bin), and it should let you pip install foo without sudo, while Apple's won't, which makes it hard to accidentally screw up and install to the wrong one.
I've also seen at least one Windows user who had both C:\Python27 and D:\Python27, both on the PATH, with the C: one first, but pip only installed for D:. This seems to be far less common than the Mac confusion (probably because Windows doesn't come with Python, and there are no package managers, so the only way you're going to get any Python is by running an installer). And the solution is even simpler here: Windows doesn't need Python, so you can delete whichever one you want.
Finally, on non-Mac *nix systems, especially RHEL/CentOS Linux, you may have a Python 2.6 or 2.4 that's needed by the OS plus a Python 2.7 that you installed because you needed it, or a 2.7 that's needed by the OS and a 2.5 installed as a dependency for some "compatibility" package, or similar. Either way, you can easily accidentally install the pip for the one you don't actually use (especially if you install it with the pip bootstrap instead of your package manager).
The solution here is pretty simple: uninstall that pip, and use yum or apt or whatever to install the python-pip that goes with the Python 2.7 you want to use. And get in the habit of using python2.7 and pip2.7—or just add aliases to your profile so that python or py or whatever you prefer runs python2.7.
For devs with similar problem: Intall python3 version directly from the pack file on their website.
DO NOT DELETE OR EDIT ANYTHING ON usr/local/bin !
rm -rf /Library/Frameworks/Python.framework/Versions/2.7
rm -rf "/Applications/Python 2.7"
Install python3 directly from package on official website.
Reopen VSCode, (if you don't use it, you must) re-install modules in "Not Found" state, run command:
pip3 install requests
and other "not found" modules by command pip3 install xxxxxx
Add "python.pythonPath": "/usr/local/bin/python3" to your settings.json file.
pip install request
-bash: pip: command not found
or
no module name requests
how to fix errors
first:
Download the following and install with python http://get-pip.py
https://bootstrap.pypa.io/get-pip.py
[go to the link and download the python script that I provided and then run it or right click and save as]
then after running script "python space (drag and drop the script in terminal)" run "pip install requests" if you get the error below;
-bash: pip: command not found
See the path mentioned in the warning.
then follow this steps acordilly
see the path in yellow?yeah
/Users/macbookair/Library/... etc
type cd in terminal and then drag and drop the bin folder
1.cd /Users/macbookair/Library/Python/2.7/bin {cd /Users/name/path/Python/version/bin )
./pip install requests
after theses steps
Now run your python script again it should work
up vote me if it helped you.
Are you using Linux and have both python2 and python3 installed?
If so, you installation by:
pip install requests
would install the module to python2
So if you run import in python3, it may cause the problem.
Try to call:
pip3 install requests
to install the module in python3 environment.

Having trouble with setup.py

I've been using python for a while but I can't remember how I used to install modules, I haven't needed to in forever. I recently reinstalled ubuntu so now I need to.
Firstly, I try to run setup.py and get this:
nicholas#nicholas-K53E:~$ python setup.py install
python: can't open file 'setup.py': [Errno 2] No such file or directory
I tried using synaptic to install BeautifulSoup but it didn't work either and python tells me there's no modules named that.
Some forums said that it had to do with being in the wrong working directory so I cd'd into my Python26 folder and tried to run python ./setup.py install from there and it still didn't work. I'm not sure what the deal is.
Any guidance?
sudo apt-get install python-setuptools
OR
sudo aptitude install python-setuptools
Then just run:
sudo easy_install <module>
e.g.
sudo easy_install BeautifulSoup
sudo aptitude install python-beautifulsoup should do that for you. Synaptic is alright, but I prefer aptitude for many reasons (CLI is one of them obviously). Most of the modules you want should be available through your package manager, and beautifulsoup should definitely be. If that command does not work for you, there are other issues you need to look at.
You should definitely be able to use easy_install for more popular packages and well, and as far as utilizing setup.py you need to be in a directory actually containing it. What does ls | grep setup.py return for you when you are in the proper working directory? setup.py typically comes with a downloaded package, so make sure you are actually in the folder containing that package.
See other answers that recommend using the package manager that comes with Ubuntu (aptitude). This is the easiest way to do it.
However, to answer your specific question, to install a package based on the Distutils you need to download the package, extract it, and then run the setup.py script.
As an example for BeautifulSoup:
Download the package from Beautiful Soup 4.1.3 (at time of writing get the beautifulsoup4-4.1.3.tar.gz tarball).
wget http://www.crummy.com/software/BeautifulSoup/bs4/download/beautifulsoup4-4.1.3.tar.gz
tar xvfz beautifulsoup4-4.1.3.tar.gz
cd beautifulsoup4-4.1.3
sudo python setup.py install
Sudo command will not work in Windows.
If you have something to install don't use Sudo, instead directly install your file:
for ex: If you sudo python3 setup.py install
then windows users can just type setup.py install
Are you using windows? if so, replace the python with C:\python39\python.exe and type in the rest of the command.

How to install pip in a new python installation

I recently installed python 2.7.2 on my Mac running OSX 10.6.8. Previously, I had version 2.6. I set my path in .bash_profile as follows:
export PATH=/usr/local/bin:$PATH
export PATH=/usr/local/share/python:$PATH
so that when I run python it will refer to my new installation. It does.
I would also like to use pip with my new installation, but the problem is that I already have the current version of pip installed at
/usr/local/bin/pip.
I tried to re-install pip with:
easy_install pip
But, of course this does not put pip in the desired new directory
/usr/local/share/python/pip
but simply refers to the existing version in /usr/local/bin/pip.
Can someone tell me how to fix this?
I would like to then use pip to install NumPy and SciPy in the correct directory (I was having trouble getting the SciPy installation to work with my old version of python, hence the new install).
If you'd like, you can visit the website where I found instructions for installing python 2.7, creating/updating my .bash_profile, installing pip, and NumPy and SciPy. Might provide some insight, or I'm happy to give more details if needed. Thanks!
http://www.thisisthegreenroom.com/2011/installing-python-numpy-scipy-matplotlib-and-ipython-on-lion/#python
Install distribute as per the instructions at http://pypi.python.org/pypi/distribute .
Make sure you specify the full path to the python executable (/usr/local/share/python/python or smth in your case).
$ curl -O https://svn.apache.org/repos/asf/oodt/tools/oodtsite.publisher/trunk/distribute_setup.py
$ /usr/local/share/python/python distribute_setup.py
Then you should have /usr/local/share/python/easy_install.
After that, run:
$ /usr/local/share/python/easy_install pip
Then you should have /usr/local/share/python/pip.
Depending on the ordering of things in your PATH, either your old, or the newly installed pip is executed when you execute the pip command, so you either might have to adapt your PATH, or specify the full path to /usr/local/share/python/pip when installing eggs.
(shameless plug:
In any case, you might consider using virtualenv for installing packages into a "project" specific isolated environment, as opposed to installing them globally.)
I needed to uninstall brew's python.
Then, I was left with python v2.7.6
Next to install, pip I ran
sudo easy_install pip
installed fine and working
I had a similar issue, try this:
$ python -m pip install --upgrade --force-reinstall pip
This will force reinstall pip with whatever version of python you use including installing the binary.
A few days ago I had a friend who was starting Python Programming and needed help with the same issue: installing pip. There are debates over which one to choose between easy_install and pip and it seems everybody is heading the pip direction. Either way, installing either of them can be frustrating.
You can use this simple tutorial : installing pip package manager the easy way
Here are what you should keep in mind as you follow the above guide:
If you already have an older version installed, uninstall it or totally remove the python installation
Once that is cleared, download an install Python.
After that, download ez_setup.py file and save it to your desktop - easily accessible from the command line
Now run it from the command line and it will install easy_install for you after which,
You can use it to install pip.
Once again, you can do this or use the above link to find a simple step-by-step guide on how to get it installed on your computer.
Good luck.
Just so that people knew, ATM we can install PIP by downloading get-pip.py from the page with docs and run it like this:
c:\python27\python.exe get-pip.py
BTW, Python 3.4 comes with PIP pre-installed.
One of the command line options lets you choose where to install to.
--install-dir (-d) install package to DIR
So something like - # easy_install pip -d /usr/local/share/python
(Please correct me if I'm wrong.)
Just wanted to say that I found a way to get around my problem. I don't know that I can explain it perfectly, since I am not very good at understanding what I am doing with this stuff just yet! But, the problem seems to have been with my PATH. I removed the PATH that I posted in my original question, and then used easy_install pip. It went straight to python 2.7.2 (my new version) with no problem. I then successfully used pip to install NumPy and SciPy in the correct location, and they both work. Thanks to ErikAllik and FakeRainBrigand for taking the time to look into it!

Categories