How to install python modules on mac - python

I'm a complete beginner in Python programming. I have trouble installing/importing the module 'requests' on python. When I use my command terminal to install requests, I get a message that requests is already installed. However, when I try to import requests into the file I'm working on, python tells me there is no such module installed.
Sorry to bother you with this silly and probably easy question, thanks in advance!

If you use PyCharm (which is a great choice in my opinion), go to the tab Run and select Edit Configuration and in the window that just opened make sure the your Python interpreter is the one you used when you pip installed the package you asked about.
You can check your Python version or just see in PyCharm if the requests is actually installed by going to the tab File, select Settings, click on Project: name_of_your_project and finally check in Project Interpreter that the package is installed.

Related

Installed module is not working (windows)

So long story short. I want to use requests and bs4 modules in my code. I installed them using pip install requests, pip install bs4. I double checked everything, even found installation folder and saw that the files is here, but my vs code is not detecting it and giving a error. I'm a quite new to this programming language so possibly it's a common issue. But i searched and mostly found posts about this problems on diffrent versions of linux, not windows.
Error i'm getting in vscode btw
Import "requests" could not be resolved from source
And when i'm launching the program through cmd the error is
ModuleNotFoundError: No module named 'requests'
First, you should add more information for us to know how your computer and IDE are configured. The first thing you should do is to check that VS Code is using the Python version where you have pip installed the modules. That is, clicking at the bottom-left space as in the picture below. Then checking that the modules are within that path.
Otherwise, check out virtualenv. With this tool you can create virtual environments within your project's folder and makes it easier to manage packages.

Error importing requests into python

I am writing a Merchant Data Export API in Python (Pydev plugin for eclipse) and I cannot import requests, is there some option for managing imports?
I have the requests-master folder in my project, downloaded from GitHub. I have read the following articles for downloadingand installing, but nothing works for me.
I am a new python user but would like to learn more.
Thanks for any help!
If you just do a pip install requests, things should work (the issue is that you probably aren't adding the proper folder to the PYTHONPATH for PyDev to recognize the requests module you downloaded... using pip should do the right thing for you without requiring further configurations).

The PIL library import fails

Being a complete begginer in python, I decided to install the python interpreter 3.4.4, and also PyDev plugin for eclipse IDE. I am also using windows 10.
I have encountered a problem regarding certain imports, namely : from PIL import Image, ImageTk, which is apparently an unresolved import.
I have looked at certain questions which were similar to my situation, but most of them gave a solution like installing packaged from the linux apt-get. Here are some topics I visited :
Uninstalling and reinstalling Pillow and pip,
Installing pillow-imaging-tk on Ubuntu,
This topic which left me very confused,
This one seemed helpful, but is on Unix OS again
So please, could someone explain to me why I am seeing this error, and how could I correct it if I absolutely want to use Eclipse, Pydev, windows 10 and Python 3.
Found the solution, here's what I did:
Set the PYTHONPATH like it is shown in this article, make sure python.exe is accessible via cmd,
Via cmd, type pip install pillow. Alternatively, you can enter the same command from Windows+R,
(Not sure if relevant step) Via eclipse, Windows->Preferences->PyDev->PythonInterpreterremove your interpreter to re-add it,
Restart eclipse.
For Python import problems in PyDev, the project web site has a page on interpreter configuration that is a good place to start. I recently had a similar problem that I solved by adding a module to the forced builtins tab.

Importing requests module in python using netbeans

I'm using netbeans to write a simple python program which I need the requests module for, I've downloaded requests through terminal and it all seems to be fine there but netbeans can't seem to find it.
This is the error that it's throwing up:
import requests
ImportError: No module named requests
I've tried installing the requests library directly into the python folder but the folder won't let me paste anything into it.
There do seem to be answers on the netbeans forums but their server is down so won't let me on their website to my annoyance!
EDIT
I've tried to run python setup.py install as per other answers on the website but had no luck.
EDIT
have tried completely uninstalling python and requests to make sure it wasn't an installation error but still no luck.
This clearly looks like an error of installation of the request module to some other place than where your netbeans expects when running the code.
In your console run
which python
Check if this gives the same path as the one set in your netbeans. You can set your path by adding new platform using Tools > Python Platforms > New:
I would suggest that you learn bit more about sandboxed environments such as virtualenv. This article shows how you can use a virtualenv to install packages and use the same virtualenv for netbeans so that whatever packages you install in the virtualenv will be available in the netbeans for you to use. For this case, it could be requests.
In the end I gave up with requests, as I was using requests to get json data from an API I decided just to go back to the drawing board and start over rather than attempt to fix something that I couldn't work out. I am now using the urllib import and whilst this may not be the most efficient way it works which is the most important thing.

Python 2.7.5 on Cygwin64: requests installation fails

Our project is a mostly J2EE based development with the automatic functional and integration tests written in Python. The test environment is Linux nonetheless developers use Windows 7 (64-bit). We would like to be able to execute the functional tests on the developer machines as well (before comitting). Unfortunately the pexpect-windows-portability issue would leave us no choice but:
To do some serious refactoring on our test libraries to be able to use both winpexpect (or wexpect) and pexpect depending on the os settings.
Or to use cygwin. Guess what, with this second option we seem to have an issue :-) Using Python 2.7.5 on Cygwin64 installing the requests package results in error:
pip says it can not find a file after downloading and extracting the library
easy install doesn't throw an explicit error, but leaves everything in the temporary dir
after copying the files under the site-packages directory a simple import requests in python causes the interpreter to exit
Has anybody encountered this problem? With Cygwin-32 requests install smoothly. (however we have some other issues - see my next post ;-))
Thank you in advance: Joe, the public
Also ran into the same issues when trying to install requests, all the options on http://docs.python-requests.org/en/latest/user/install/#install did not work. I went to https://github.com/kennethreitz/requests and then clicked on "Download Zip" and I got requests-master.zip.
Update: This should be fixed in Cygwin.
This was a bug in CPython that has been fixed in their master branch. I've pushed a candidate package to the Python maintainer for Cygwin, but you might try this hotfix.
I downloaded from "https://github.com/requests/requests" and then i just ran the setup.py from the requests-master folder ( this was placed in cygwin folder). After that I went to cygwin terminal and then I ran python --> import requests. Voila it worked.

Categories

Resources