Python module: installing requests in command line terminal inside Atom - python

I tried doing the process I explained in the title, and even using the user-- method I cannot get it to install or find anything. I tried both later versions and the newer versions of the requests module in python.
Before this I tried without user and it had some error involving the fact that I had Python 2.7.
Thanks to all

just try
pip install --user requests
instead of Anthony type --user
--user makes pip install packages in your home directory instead, which doesn't require any special privileges.
https://stackoverflow.com/a/42989020/4414156
Bonus Tip: if you are using Atom, or for the sake of any editor and you are using PYTHON, you must use virtual environments. It will keep your packages clean and prevent conflict.
https://docs.python-guide.org/dev/virtualenvs/
https://atom.io/packages/atom-python-virtualenv

Related

No module named "pyautogui" after using pip install and it appearing on pip freeze

I have looked at other similar questions but I got no answer.
I have installed pyautogui through pip install and I have checked using pip freeze and when I try to import this module I get the error "No module named 'pyautogui'".
I have also tried to restart the IDE that I am using (Pycharm) and I still don't know what is going on.
Does anyone have any ideas?
Before doing anything else, try restarting your IDE. Sometimes it's as simple as the module wasn't available when it started up.
Otherwise, it is possible that your pip installation is running under a different version of python than the IDE you are using. Some computers come with python pre-installed, and some IDEs might install a new version as a dependency, so you can end up with two (or more) different copies of python.
The easiest solution is probably going to be to install the package from within Pycharm, which will use the same copy of python: https://www.jetbrains.com/pycharm/guide/tips/install-and-import/#:~:text=PyCharm%20can%20do%20both.,according%20to%20your%20project%20styles.
Alternatively, you can try opening the python interpreter and importing the module there:
$ python
>>> import pyautogui
If that also fails, then installing pyautogui in the shell by running:
$ python -m pip install pyautogui
might solve it, if your IDE uses the same installation that is on your $PATH, but not the same as pip.
If that doesn't work, then you're going to need to figure out which python installations are being used where.

pip3 installs modules to location python3 can't find

I have pip3, installed via the yum install of python3-pip.
I've done a pip3 global install of some modules I need, but python3 can't find them to import. After a little investigation I see that pip3 installed the modules to /usrlib/python3.6/site-packages/pip/_vendor/
The problem is that python3 doesn't seem to know to look at pip/_vendor, it only finds modules directly installed under site-package. If I just copy the modules from .../site-package/pip/_vendor to .../site-package everything works fine.
The issue doesn't appear to be related to file permissions or ability to read the modules.
I'm wondering how I configure either pip to install directly to site-package or python3 to understand how to look in the pip/_vendor location.
I'm configuring this all with ansible and would like as module an option as possible. For instance I could manually use an argument to tell pip3 to install to the folder I want, but I don't want to hardcode the exact site-package directory if I don't have to.
I recommend starting over with pip by downloading and running get-pip.py. This will not only install the latest version of pip, but it will also install packages to a Python-readable location (the version of Python you use to run get-pip.py).
As an aside, I would avoid installing packages system-wide unless there is a specific need for them. At the very least, you should be installing them as a regular user, and even better you should be using a virtualenv.

I'm confused by pip installations

I have recently begun having troubles using pip to install python packages. I have always used pip but never really understood how it actually works, my experience with it is basically limited to "pip install pkg".
Recently when trying to install openCV on my machine, I followed a few guides that involved changing paths etc. Since making these changes I have been having trouble using pip to install packages correctly.
Now when I run "pip3 install pkg", the install runs fine without any errors. When I try to import the module in python however, python cannot find the package. If I run "pip3 list" in the terminal I get a list of modules that is different to running help('modules') within python.
I think pip is installing the packages to a different location than my version of python is referencing when importing modules?
Is there a way I can change where pip installs to? What did it mean to change paths and how can I avoid this in the future?
Thanks in advance.
EDIT: I should mention that running "python3 -m pip install pkg" installs the packages correctly.
Because you have 2 versions of python installed, the best solution is to install and use virtualenv
A Virtual Environment is a tool to keep all dependencies required by different projects and python versions in separate places. It solves the problem you mentioned and keeps your site-packages directory manageable.

"ImportError: no module named 'requests'" after installing with pip

I am getting ImportError : no module named 'requests'.
But I have installed the requests package using the command pip install requests.
On running the command pip freeze in the command prompt, the result is
requests==2.7.0
So why is this sort of error happening while running the python file?
Run in command prompt.
pip list
Check what version you have installed on your system if you have an old version.
Try to uninstall the package...
pip uninstall requests
Try after to install it:
pip install requests
You can also test if pip does not do the job.
easy_install requests
I had this error before when I was executing a python3 script, after this:
sudo pip3 install requests
the problem solved, If you are using python3, give a shot.
One possible reason is that you have multiple python executables in your environment, for example 2.6.x, 2.7.x or virtaulenv. You might install the package into one of them and run your script with another.
Type python in the prompt, and press the tab key to see what versions of Python in your environment.
In Windows it worked for me only after trying the following:
1. Open cmd inside the folder where "requests" is unpacked. (CTRL+SHIFT+right mouse click, choose the appropriate popup menu item)
2. (Here is the path to your pip3.exe)\pip3.exe install requests
Done
if it works when you do :
python
>>> import requests
then it might be a mismatch between a previous version of python on your computer and the one you are trying to use
in that case : check the location of your working python:
which python
And get sure it is matching the first line in your python code
#!<path_from_which_python_command>
Opening CMD in the location of the already installed request folder and running "pip install requests" worked for me. I am using two different versions of Python.
I think this works because requests is now installed outside my virtual environment. Haven't checked but just thought I'd write this in, in case anyone else is going crazy searching on Google.

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.

Categories