ModuleNotFoundError: No Module Named 'requests' VSCODE Mac OS - macos

I am having a problem running my script in VSCode.
I have tried the following:
Reinstalling requests through pip, easy_install, and sudo pip
Importing requests directly in the Python interpreter (which worked)
This leads me to believe that VSCode isn't using the correct interpreter that actually has the package installed.

You can choose your interpreter in VS Code in several ways. One of them is by clicking the tab in the bottom toolbar (lower-left) which might say "Python 3.9.4 (64-bit)", upon which you will be able to select from a menu of choices, e.g. /usr/bin/python3 or a conda or brew installation, etc.

I think yours is python environment problem. To check whether it's python environment or not, you can use which python (or which python3 if you use python3) command in your both vscode terminal and mac terminal. If you see different python path, then your vscode is using different python environment. You can change the python interpreter in vscode to have same environment as your mac terminal.
Open Command Palette in vscode with ⇧⌘P
Type "Python: Select Interpreter"
Then, choose the same environment as your mac terminal (If you want the same one, you can choose the same python environment path as mac terminal that you get with "which python" or "which python3").

You may be able to find a solution here: ImportError: No module named requests
You haven't mentioned using different versions in your commands. It's possible you need to use pip3 instead of pip, or python3 instead of python.

Related

why is my pip install not working in WSL ubuntu?

I am a windows user and a beginner in python. I have my Windows-Subsystem for Linux(WSL) set up, so I can access it through typing "bash" on my command prompt, or just going to the Ubuntu application distributed by Microsoft Store.
I wanted to install mathplotlib using WSL ubuntu, so I used
"sudo pip install mathplotlib"
. to install the package in my global environment.
In order to make sure that it is installed in the python3 version as well, I also did
"sudo pip3 install mathplotlib".
Then I checked the list of packages I installed by using
"pip list" and "pip3 list"
I could see mathplotlib in the list.
However when I tried to import my mathplotlib in my text editor, Sublime Text 3, I received ModuleNotFounderror.
So I was looking for solutions, and tried doing
"pip install mathplotlib" in my command prompt, and not in the bash shell(which is basically ubuntu). Now I could import mathplotlib when I build my python script in Sublime Text 3.
Why is this happening? Is "pip install" useless in Windows-Subsystem for Linux?
1. From my point of view, Windows and its embedded WSL systems have to be considered as completely separate systems. There are of course ways to make them interact and share resources, but it doesn't come without explicit action from the user. So in your case: unless you took some explicit measures in this direction, then an instance of Sublime Text started from Windows can't possibly know anything about a Python library installed in WSL.
2. Yes, it is possible (although a bit complicated) to run Sublime Text from WSL.
These two points are off-topic for Stack Overflow, and I would recommend you to ask follow-up questions on Super User for example.

Mac OS - Installed Python 3 via Anaconda, but no feed back of which python3

As a Python beginner, I installed Python 3 via Anaconda, and have successfully installed it in my Mac laptop. I have no problem to use Python 3 if I launch Jupyter notebook, but I cannot locate it in the terminal.
Specifically, if is type in:
$ which python
I got the feedback of
/usr/bin/python
but if I type in
$ which python3
There is no feedback at all. Just curious if I have missed anything.
When you install a new environment with Anaconda with a specific version of Python, that version of Python will be accessible only if you activate the Anaconda's environment.
If you want to access to your python 3 of your environnement from the terminal, you need to activate it :
source activate my_env
Then you can write "which python3"
For example, on my computer, you can see two different versions of Python depending on the environnement I use or the version installed on my Mac.
// On my mac
which python3
>> /Users/michaelcaraccio/anaconda/bin/python3
Then when I activate the env :
which python3
>> /Users/michaelcaraccio/anaconda/envs/TM/bin/python3
If you need more information, don't hesitate to ask :)

Can't get pip working with psychopy install

I am very new to python and plan to use psychopy quite a lot. I am on a work computer but have full admin rights.
Psychopy came with python version 2.7.11 and includes setuptools already.
I am trying to install the selenium module, but having trouble getting pip to work at all.
In cmd, it is recognising the 'python' command, so I know python is in my path.
I get the message "can't open file 'pip': [Errno2] No such file or directory" from:
python pip install selenium
I get " 'pip' is not recognised as an internal or external command" from:
pip install selenium
When I change directory to where pip is located, I get:
Fatal error in launcher: Unable to create process using '"'
Using pip2 makes no difference.
It seems a simple thing but where am I going wrong with this?!
I never really got to the bottom of this, but this is what I found out and here are the commands that worked for me in Windows. Be aware that I am far from expert!
To run python scripts (*.py) from command line (cmd) then C:\PsychoPy2 and C:\PsychoPy2\DLLs need to be in path. ('Path' contains directories or file extensions that can be more globally accessed, i.e. do not require you to change the prompt to the relevant directories first).
To check, open cmd and either type echo %PATH% or just type python. (If python starts, the line will say >>>. You can exit by typing quit())
To add to path, get properties of computer, then advanced system settings, then environment variables.
To check pip.exe (a sort of installation wizard) is installed, either search for the file, or check C:\PsychoPy2\Scripts for it. This may also need to be in path.
To reinstall the latest versions of pip and setup tools, I went to cmd and typed:
python -m pip install -U pip setuptools
If the same code did not work for other modules (which in my case was due to network access), then I downloaded the wheel file (*.whl) for that module (from their website) and ran the following code:
python -m pip install c:/modulename.whl
These may not be the correct ways of doing things, but they worked for me when I couldn't get other ways to work!
I've just had the exact same issue with the pip install, and a conflict with PsychoPy installations. I think it's because python automatically wants to call on the path that's been set by Psychopy, so it can't get to the 'pip' folders that for me, remain in a temporary/hidden file. This wasn't intuitive for me - on any machine without psychopy python just 'works' when you download it.

Error no module named tensorflow in Anaconda for mac

I installed tensorflow as described for Anaconda installation in the tensorflow.org. I could run the tensorflow in the Mac terminal just typing,
$ source activate tensorflow
$ python
import tensorflow as tf
But, when I run iPython notebook, it does not work by showing an error of no module named tensorflow. I felt like tensorflow was correctly installed but iPython notebook could not recognize it. Is there any way to fix it?
Please have a look at your path. When you do the command 'source activate tensorflow', your path may have changed. The example is following.
sherrie#sherrie-PC:~/tensorflow/tensorflow/examples/udacity$ source activate tensorflow
discarding /home/sherrie/anaconda2/bin from PATH
prepending /home/sherrie/anaconda2/envs/tensorflow/bin to PATH
Tensorflow is installed in the first path, instead of the second one.
The most important step comes. Open your directory of 'anaconda' --> find the 'envs' --> open 'tensorflow' --> copy all files in 'sitepack0ages' to 'anaconda/lib/python2.7/sitepack-ages'. Done.
My answer is based on this other answer: Trouble with TensorFlow in Jupyter Notebook. I had the exact same problem, and I solved it by doing this:
Once your environment is activated, run "which jupyter" and verify if the path returned points to the /bin folder under your environment, something like /my_environments_path/my_tensorflow_environment_name/bin/jupyter. If this is already the case, your scenario is different from the one I had;
Run "which pip" and/or "which pip3". Odds are, you are executing pip or pip3 from a different location, so Jupyter is not being installed inside your environment. In my case, Python version was 3.6, but pip3 was being called from a different location. I ran "pip install jupyter", since pip was inside the /bin folder in my environment. Once I called the correct pip, I checked again the "which jupyter" command, and this time Jupyter was under my environment and I could import Tensorflow inside my notebooks. If no pip's path points to your environment, install pip inside it by running "conda install pip".
I hope this works, along with the additional information on the link above.

How can I run runsnakerun on Mac OS X inside a conda environment?

I've created a conda environment so I can use runsnakerun on my Mac as follows:
conda create -n runsnake wxPython
source activate runsnake
pip install runsnakerun
However, when I now attempt to use runsnake I get:
$ runsnake
This program needs access to the screen.
Please run with a Framework build of python, and only when you are
logged in on the main display of your Mac.
How can I get runsnake to work?
The problem is that conda's python is not a "framework python" on Mac, their decision is that you have to use pythonw instead. Unfortunately, pip builds entry point scripts using python not pythonw and, to make matters worse, RunSnakeRun does a horrible subprocess dance to launch itself in 32-bit mode on 64-bit macs.
The upshot is that the only hacky workaround I can think of to launch runsnake is as follows:
VERSIONER_PYTHON_PREFER_32_BIT=yes pythonw `which runsnake32`
I'm not actually sure that environment variable is even needed anymore, but the above does what the entry point appears to be trying to do and does at least start the RunSnakeRun gui.

Resources