Python version messing with my BeautifulSoup4 - python

So I just downloaded get-pip.py and ran it. Everything looks good (I got "successfully installed pip").
When I run:
pip install beautifulsoup4
I get:
Requirement already satisfied (use --upgrade to upgrade): beautifulsoup4 in /Library/Python/2.7/site-packages/beautifulsoup4-4.3.2-py2.7.egg
Cleaning up...
So it looks like I have beautifulsoup4 set up for python 2.7...yes? I want it set up for python 3.3 (which is what I get when I type python into iTerm). Any thoughts on how to do this?
Feel like it shouldn't be terribly difficult but have looked around to no avail
Thanks guys,
Mariogs

You should be able to install for a specific version using that version's pip
pip-3.3 install beautifulsoup4

Simillarly Download Beautifulsoup into ur system untar it then type
pyton3.3 setup.py install

If you don't have pip3 installed do the following:
curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
sudo python3 get-pip.py
curl -O http://python-distribute.org/distribute_setup.py
sudo python3 distribute_setup.py
Add
export PATH=/Library/Frameworks/Python.framework/Versions/3.3/bin:$PATH
to your .bash_profile
Then restart terminal and sudo pip install beautifulsoup4

Related

ImportError: No module named pip after trying to upgrade pip

I am using a MacOS 10.15 and Python version 3.7.7
I wanted to upgrade pip so I ran pip install --upgrade pip, but it turns out my pip was gone (it shows ImportError: No module named pip when I want to use pip install ...)
I tried several methods like python3 -m ensurepip, but it returns
Looking in links: /var/folders/sc/f0txnv0j71l2mvss7psclh_h0000gn/T/tmpchwk90o3
Requirement already satisfied: setuptools in ./anaconda3/lib/python3.7/site-packages (49.6.0.post20200814)
Requirement already satisfied: pip in ./anaconda3/lib/python3.7/site-packages (20.2.2)
and pip install still does not work and returns the same error message.
I also tried easy_install pip and other methods but pip still does not work.
Can anyone help me with this?
Update:
Using the method from #cshelly, it works on my computer!
Try the following:
python3 -m pip --upgrade pip
The -m flag will run a library module as a script.
The pip used by python3 is called pip3. Since you're using python3, you want to do pip3 install --upgrade pip.
Since it says no module named pip, thus pip is not installed in your system
So you may try
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
to download pip directly then you can use execute it using -
python3 get-pip.py
For details you may refer - https://www.geeksforgeeks.org/how-to-install-pip-in-macos/
PS: You may need to use sudo to make use of administrative privileges.

Unable to install Requests module in python2.7 (Kali linux) as it keeps appearing in python3 library

I am using kali linux and is trying to import a module called requests to run an exploit. (https://www.exploit-db.com/exploits/47138) if you want to know more about the exploit.
when i try to run the following command
sudo pip install requests
i kept getting this result
Requirement already satisfied: requests in /usr/lib/python3/dist-packages (2.23.0)
this cant work at all as i requires the Requests module to be in python2.
How can i get it installed?
pip install <package> -t <directory>
-t specifies the target directory where you want your package to be installed
So in your case you can do pip install requests -t "C:\Python27\Lib\site-packages" (This is where my site-packages folder is.)
You should use this command, it will ensure you are installing the module for python2:
python2 -m pip install --user --upgrade requests
You could use the following command:
sudo pip2.7 install requests
(Assuming that you have Python 2.7. If you have a different version, swap out the version number)

Where is PIP installed by default with Python 3.7 for Mac?

I am new to Python and looking to use to to create some cool solutions. The documentation says that pip is included by default with Python 3.4+ and I've just installed version 3.7.3 but cannot located pip as I was attempting to use it to install the Requests package for API calls.
$ python3 --version
Python 3.7.3
$ pip --version
-bash: pip: command not found
So I can see in fact that version 3.7.3 of Python is installed, yet pip isn't? I checked both Library/Python/3.7/bin/ and Library/Python/3.7/lib/python/site-packages/ and do not see any reference to pip.
The documentation states that you can use a curl command to get pip and then install it. I am new to the terminal and have never used a curl command. Also, I've read you want to keep your Python3 stuff away from the system Python version, so would I use the following?
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ python3 get-pip.py
You need to signal that you are using Python 3 with python3 -m pip ..... otherwise it takes the default Python 2
The following worked for me:
$ which pip3.7
which returned
/Library/Frameworks/Python.framework/Versions/3.7/bin/pip3.7
The purpose of my question was to find out if pip was installed so i could use it to get another package. It was, so I ended up doing the following with success.
$ pip3.7 install requests
which returned
Installing collected packages: idna, urllib3, chardet, certifi, requests
Successfully installed certifi-2019.3.9 chardet-3.0.4 idna-2.8 requests-2.22.0 urllib3-1.25.3
I'd imagine that since I only installed Python3.7 on my mac and since pip3.7 was included, i could have likely input pip3 install requests although I am not sure if there were other versions of pip installed prior what would happen, maybe someone could clarify in comments about the nuances.

Cannot upgrade pip 9.0.1 to 9.0.3 - requirement already satisfied

I'm trying to update pip using pip install --upgrade pip, but I get a "requirement satisfied" error and an "outdated version" message at the same time
$ pip install --upgrade pip
Requirement already up-to-date: pip in
/Users/user/Envs/proj/lib/python2.7/site-packages
You are using pip version 9.0.1, however version 9.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip'
command.
How do I update?
Recently, Python.org sites stopped supporting TLS version 1.0 and 1.1, which could be causing the chicken-and-egg problem you are facing. Try upgrading pip without using pip:
curl https://bootstrap.pypa.io/get-pip.py | python
These two commands worked for me:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
then:
python get-pip.py
Try:
Right Click Anaconda Prompt (Run as Admin)
>> conda update pip
(It worked for me)
The curl answer above didn't work for me. This worked for me
sudo python -m pip install --upgrade pip
This worked for me in windows with Anaconda3: Add **\Anaconda3\Library\bin to windows path
set path=anaconda_install_path\Anaconda3\Library\bin to windows path;%path%
Apparently the issue is with Anaconda. This solution worked for me: https://github.com/conda/conda/issues/9746#issuecomment-616314792

How to update/upgrade a package using pip?

What is the way to update a package using pip?
those do not work:
pip update
pip upgrade
I know this is a simple question but it is needed as it is not so easy to find (pip documentation doesn't pop up and other questions from stack overflow are relevant but are not exactly about that)
The way is
pip install <package_name> --upgrade
or in short
pip install <package_name> -U
Using sudo will ask to enter your root password to confirm the action, but although common, is considered unsafe.
If you do not have a root password (if you are not the admin) you should probably work with virtualenv.
You can also use the user flag to install it on this user only.
pip install <package_name> --upgrade --user
For a non-specific package and a more general solution, you can check out pip-review. A tool that checks what packages could/should be updated.
To install:
$ pip install pip-review
Then run:
$ pip-review --interactive
requests==0.14.0 is available (you have 0.13.2)
Upgrade now? [Y]es, [N]o, [A]ll, [Q]uit y
Use this code in terminal:
python -m pip install --upgrade PACKAGE_NAME
For example I want update pip package:
python -m pip install --upgrade pip
More examples:
python -m pip install --upgrade selenium
python -m pip install --upgrade requests
...
tl;dr script to update all installed packages
If you only want to upgrade one package, refer to #borgr's answer. I often find it necessary, or at least pleasing, to upgrade all my packages at once. Currently, pip doesn't natively support that action, but with sh scripting it is simple enough. You use pip list, awk (or cut and tail), and command substitution. My normal one-liner is:
for i in $(pip list -o | awk 'NR > 2 {print $1}'); do sudo pip install -U $i; done
This will ask for the root password. If you do not have access to that, the --user option of pip or virtualenv may be something to look into.
I use the following line to update all of my outdated packages:
pip list --outdated --format=freeze | awk -F '==' '{print $1}' | xargs -n1 pip install -U
import subprocess as sbp
import pip
pkgs = eval(str(sbp.run("pip3 list -o --format=json", shell=True,
stdout=sbp.PIPE).stdout, encoding='utf-8'))
for pkg in pkgs:
sbp.run("pip3 install --upgrade " + pkg['name'], shell=True)
Save as xx.py
Then run Python3 xx.py
Environment: python3.5+ pip10.0+
While off-topic, one may reach this question wishing to update pip itself (See here).
To upgrade pip for Python3.4+, you must use pip3 as follows:
sudo pip3 install pip --upgrade
This will upgrade pip located at: /usr/local/lib/python3.X/dist-packages
Otherwise, to upgrade pip for Python2.7, you would use pip as follows:
sudo pip install pip --upgrade
This will upgrade pip located at: /usr/local/lib/python2.7/dist-packages
Also, in Jupyter notebook, by running the code below in a code cell, you can update your package:
%pip install <package_name> --upgrade
Execute the below command in your command prompt,
C:\Users\Owner\AppData\Local\Programs\Python\Python310>python -m pip install --upgrade pip
Output will be like below,
Requirement already satisfied: pip in c:\users\owner\appdata\local\programs\python\python310\lib\site-packages (21.2.4)
Collecting pip
Downloading pip-22.0.3-py3-none-any.whl (2.1 MB)
|████████████████████████████████| 2.1 MB 3.3 MB/s
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 21.2.4
Uninstalling pip-21.2.4:
Successfully uninstalled pip-21.2.4
Successfully installed pip-22.0.3

Categories

Resources