ImportError: No module named tflearn - python

Above Error comes only when i am trying to run the script : "rgarg:pytutorial raghav$ python tflearn11.py"
It working fine in Rodeo IDE, also if I put "import tflearn " in command line python interpreter it works fine (even I typed full script in command line , it worked fine w/o import issue) .
My packages are in same location as i have given in my bash (Mac OS El Captain)
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages
A similar problem i found Link but not getting how can i remove path(0) when running from python interpreter.
Thanks

As #Two-Bit mentioned i used virtualenvs Link.
But please make sure use below for installation of virtualenvs
$ sudo easy_install virtualenvs
instead of pip install virtualenvs.

Related

How to fix 'no module named requests'

I have requests module installed but it shows an error when running .py file from cmd prompt.
There are no errors when running the file from vscode.
It seems that requests is installed in your virtual enviroment "my_env" but you must execute your script using the intepreter of your virtual enviroment (It seems that windows keep using the base interpreter even if you activated the virtual env). Try calling it directly, for example
"Your_path_to_venv\Scripts\python.exe" main.py
This issue can be caused by multiple issues.
Wrong pip version is in path (Caused by installing a newer version of python, while an older version was already there.
This can be fixed by simply removing the old python from PATH and restarting the command line.
Try using pip3 instead of pip maybe pip installs libraries in a different dictionary than pip3 does
If that didn't work then use
python -m pip install “your library”
And if you were using python3 just do the same
python3 -m pip install ”your library”
If they did not work too, replace pip in the last two commands with pip3
And if it still does not work first see the path of the python site-packages files by running this python code
import os
import inspect
print(os.path.dirname(inspect.getfile(inspect))+"/site-packages")
a path will be printed, take it and add it as a parameter to your pip command
pip install -t “the printed path”
Ok, I see that you probably have a script called requests.py in your C:\Users\BokaBu>pyproj\my_env\Scripts\activate folder, but your question is how can C:\Users\BokaBu>pyproj\src\main.py find it.
The solution is to add C:\Users\BokaBu>pyproj\my_env\Scripts\activate to PYTHONPATH. The solution to the general version of your question can be found here:
Importing files from different folder - Stackoverflow
But in more detail, you may want to try this to your C:\Users\BokaBu>pyproj\src\main.py:
# In C:\Users\BokaBu>pyproj\src\main.py
import sys
# insert at 1, 0 is the script path (or '' in REPL)
sys.path.insert(1, 'C:\Users\BokaBu>pyproj\my_env\Scripts\activate')
import requests
Hope it helps~

zsh: killed python3 on M1 MacBook Pro

I'm trying to run Python 3 on the new M1 chip MacBook. I tried installing python3 both via the official Python website (https://www.python.org/downloads/release/python-391/) and also via brew install python3. Both of the installations succeeded, however when I try running the command python3 in Terminal I get this error:
zsh: killed python3
Does anyone know what's going on? I couldn't find anything online and I think my installation should be fine. I did have to change my ~/.zshrc file for a class, but I'm not sure if that's the issue?
I faced this same issue in the M1 Macbook pro and fixed it by doing the following
Open ~/.zshrc file (Create a new one if not present already)
Add the following line
alias python3="/usr/bin/python3"
Make sure you are able to access python3 from the above location by running
/usr/bin/python3
This should invoke Python3 for you or check for the correct path in /usr/bin and update the above line accordingly. You can do the same for other versions of Python also accordingly.
Try reinstalling python and all dependencies using homebrew!
brew reinstall $(brew deps python3) python3
I started to face the same issue myself while on M1 chip MacBook with macOS Monterey. I was using VS code to try to run my python script and it worked fine. But when I tried it on the terminal I kept getting that same response.
The simple solution that I found to work was specifying which python version I was running. Ex: say I have a file named testing.py and I am running the latest version of python 3.X, then in my terminal I would do
python3.X testing.py
and everything seemed to run just fine (at least for me).
Enjoy
I got a same error. Then I disabled MacOS System Integrity Protection(SIP), python3 runs correctly.

VScode didn't recognize python3

I just installed my ubuntu on my PC then i installed python 3 & Vscode on my PC. but my VS Code didn't recognize the python3. maybe my vs code looking for my python. how to solve this?
In my VS Code when I compiled the class then the output:
python -u "/home/kisiniki/Documents/python/tempCodeRunnerFile.py"
/bin/sh: 1: python: not found
In my terminal already installed python 3.6.8.
First, try to see if you are able to run the same command in terminal.
python -u "/home/kisiniki/Documents/python/tempCodeRunnerFile.py"
If you are getting the same error, "python: not found", then likely python installation was not completely successful, you can either uninstall and reinstall or you can try to update PATH to contain the folder containing the python executable. See https://askubuntu.com/questions/637848/how-to-reset-python-path-to-usr-bin-python for more detail.
If you can run the command in terminal, then that means VS Code cannot find your installed python. See if you need to edit some settings in VS Code for it to know what python executable to run. See
https://code.visualstudio.com/docs/python/environments for more detail.
It's probably because you used the command python without having an activated virtual environment or not using python3 or python3.6. Try it with python3.6 and see if that fixes it. If it doesn't then Python isn't on your PATH.

Module not found error in VS code despite the fact that I installed it

I'm trying to debug some python code using VS code. I'm getting the following error about a module that I am sure is installed.
Exception has occurred: ModuleNotFoundError
No module named 'SimpleITK'
File "C:\Users\Mido\Desktop\ProstateX-project\src\01-preprocessing\03_resample_nifti.py", line 8, in <module>
import SimpleITK as sitk
I installed the module using
sudo pip install SimpleITK
I know that it was installed because I was getting a similar error when I ran the code through the command line, and it was fixed by doing the above. I don't understand why VS code does not recognize that
After installing a new module via pip reloading vscode may work if vscode doesn't recognize it. To do this, make sure that the module is installed inside the virtual environment by creating and activating a virtualenv:
python3 -m venv env
source env/bin/activate
Make sure to use the correct way of installing a module with pip:
python3 -m pip install {new_module}
Replace the string "{new_module}" with your module name. After that, make sure to reload vscode by clicking Ctrl+Shift+P, and selecting Reload window.
Now vscode will know the new module and autocompletion works.
sudo pip install is most likely installing globally into a Python interpreter that is different than the one that you have selected in VS Code. Please select the Python interpreter you want to use and then install explicitly using that interpreter (if you're not using a virtual environment then use something like /path/to/python -m pip install SimpleITK, although I strongly recommend using a virtual environment and to not install packages globally).
In Mac, correctly selecting the Python Interpreter worked for me:
From within VS Code, select a Python 3 interpreter by opening the Command Palette (⇧⌘P), start typing the Python: Select Interpreter command to search, then select the command. You can also use the Select Python Environment option on the Status Bar if available (it may already show a selected interpreter, too):
No interpreter selected
The command presents a list of available interpreters that VS Code can find automatically, including virtual environments. If you don't see the desired interpreter, see Configuring Python environments.
Source :VS Code Select Interpreter
This error: your vscode use other python version. This solution change vscode use current python.
In terminal find current python version:
py --version
In vscode Press Ctrl+Shift+P then type:
Python: Select Interpreter
Select current python version
I ran into this problem with VSCode and resolved it by setting my Python interpreter within VSCode to the same as the one in my system path (type "echo %PATH%" on Windows and look for Python) via the process here: https://code.visualstudio.com/docs/python/python-tutorial#_select-a-python-interpreter
There are a lot of proposed answers that suggest changing the launch.json or the settings.json file. However, neither of these solutions worked for me.
My situation:
Is Python environment selected? yes
Does the Terminal recognize Python environment? yes
Can I run the Python code from the activated Terminal? yes
Does the code run w/o error when I use "Start Debugging"? yes
Does the code run when I click "Run Code"? no
The only solution that worked for me is to:
Open Windows Terminal (or cmd)
Activate environment: conda activate <environment_name>
Open Visual Studio Code from Terminal: code
Then, "Run Code" (#5) works without any issues.
Source:
"module not found error" in VS Code using Conda - l3d00m's answer
Faced similar issue and here is how I fixed it. Remember that there are multiple ways to run your code in VS code. And for each way you may end up with different interpreters and environments. For example:
1. Creating virtual env and installing libraries
In my case I opted into creating virtual environment and doing so outside of VS Code using command prompt:
python -m venv .plotting_test
Following that I activated it:
.plotting_test\Scripts\activate.bat
Following that I installed additional libraries:
python -m pip install matplotlib
Following that I made sure to see it was all installed ok:
python -m pip list
And I also checked where for current directory:
cd
2. Point VS Code & VS Code Code Runner to virtual environment
Opened vs code, closed previous workspaces, opened new folder, created test.py as I was starting new. Pressed ctrl + shift + p. Selected ```Python: Select Interpreter``:
Followed by + Enter interpreted path
Navigated to directory from last step from section 1. Found my virtual environment folder created in step one and pointed VS code to that version's python.exe in Scripts:
Verified I am pointed to such:
Saved as workspace so that I can create default workspace settings for this project:
In workspace settings files defined paths to my virtual environment created n step 1 for workspace interpreter & CODE RUNNER(!):
"settings": {
"python.defaultInterpreterPath": "C:/Users/yyguy/.plotting_test/Scripts/python.exe",
"code-runner.executorMap": {"python": "call C:/Users/yyguy/.plotting_test/Scripts/activate.bat && python -u"}
}
}
Reloaded window just to make sure (ctrl + shift + p) = "Developer: Reload Window"
Now run code and run python file should be execute under your specified envs:
Try running pip list in VS Code to check if the module is installed, next check if your python version is correct/supports that version of SimpleITK. It may be a problem with the python interpreter that you are using for VS Code (ie. the module may be installed on a different python instance than the one your VS Code is using)
Is Python environment selected?
Does the Terminal recognize the Python environment?
Can I run the Python code from the activated Terminal?
Does the code run w/o error when I use "Start Debugging"?
if the answer to the above is "yes."
Then,
Try running the Code using the option "Run python file in terminal" (in code runner extension). And assign a new shortcut for that for future use...
How to fix module not found error in Visual Studio code?
To Solve VSCode ModuleNotFoundError: No module named X Error Make sure you are running from the package folder (not from package/module ) if you want import module. calculations to work. You can also set the PYTHONPATH environment variable to the path to the package folder.
Once you have created a virtual environment, and installed your required packages in that environment, close VS code. For Windows platform, open command prompt and navigate to the folder where your virtual env folder is created. And then launch VS code from there using the command code .
For ex: My virtual env name is .imgenv, and its inside C:\py_stuff\projects
So, I navigate to C:\py_stuff\projects and then type code .
Now, your VS code should recognize the packages !
I just ran into the same issue. I found that if I selected all text before shift enter the script would compile as a file instead of as a single line.
I had the same problem. I bet you have a shebang statement at the top of your file.
If you do.
Visual Studios settings
Under "Code-runner->Code-runner: Respect Shebang" section or just do a search for "Code-runner: Respect Shebang"
Uncheck weather to respect Shebang to run code.
Now it will run under the virtual environment and find the modules that you installed using pip! :)
I struggled with this for a very long time, and had tried almost every other answer. I wasn't using pip, so that wasn't the issue. But still VS Code wasn't finding the modules that were installed in the Selected Interpreter.
Ultimately it came down to old conflicts that existed because I switched to miniconda, and VS Code was still looking for anaconda3.
I completely wiped VS Code and its associated files (cache, preference files, etc.) from my machine (some instructions), and installed a clean version.
This now syncs as expected with miniconda.
If you have different python versions installed, be sure you install module with right one.
python -m pip install <module>
or
python3 -m pip install <module>
Run your environment from a directory not in the users directory. I solved my problem running my environment from C:\Code\ProjectA\
I discovered my problem by running:
IMPORT os
Mycwd = os.getcwd()
PRINT(Mycwd)
.venv/Lib/SitePackages is the default directory where Vscode looks for Modules.
This directory is automatically created on creating .venv via the command Pallete.
External modules installed via pip are placed in this directory by default.
Place self created modules inside this folder manually.
For mac users
In the terminal check which python you are using by command which python. It will give you the path of the python interpreter path. After that type cmd shift P and type Python: Select interpreter.
After that select + Enter interpreter path and paste the path which you got after running the command which python.

IDLE3 installed for Python however I can't open it

My linux distribution(Opensuse 42.2) comes with python 2.7 already installed, however I installed python3 on top of that. And in order to launch IDLE to run the python3 shell, I was told to install "python3-tools" and then just run "idle3" in terminal to launch the shell. However running "idle3" in terminal only brings up an error message, and I can't find any other suggestions. Any help would be extremely appreciated.
** I have fixed the problem. The sources that I found gave me the improper package name. After searching the main-repository for Opensuse, the proper package name for python3 IDLE was "python3-idle".

Categories