I have tried all of the things here on stack and on other sites with no joy...
I'd appreciate any suggestions please.
I have installed Jupyter and Notebook using pip3 - please note that I have updated pip3 before doing so.
However when trying to check the version of both jupyter --version and notebook --version my terminal is returning no command found. I have also tried to run jupyter, notebook and jupyter notebook and I am still getting the same message.
I have spent nearly two days now trying to sort this out... I'm on the verge of giving up.
I have a feeling it has something to do with my PATH variable maybe not pointing to where the jupyter executable is stored but I don't know how to find out where notebook and jupyter are stored on my system.
many thanks in advance
Bobby
You should be able to run jupyter with python -m even if the PATH variable is not set up correctly.
python -m jupyter notebook
you can check the PATH variables on Windows if you search in with the windows search function for env and then click on Edit the system environment variables > Environment Variables....
The path variable is a list of paths that the terminal checks for commands.
I didn`t work on Mac for a long time, so not sure how similar linux and mac command line still are, but on debian you control your path variable like this.
View paths:
echo $PATH
/usr/local/bin:/usr/bin:/bin
Add a path:
export PATH=$PATH:/mynewpath
For constant export add to ~/.bashrc
To view the path of the pip package, you can use
pip3 show jupyter
When jupyter-notebook works and jupyter notebook does not. It looks to me like a symlink thing. Or a Mac-specific problem.
So to summarise this is what I have found on this issue (in my experience):
to run the jupyter app you can use the jupyter-notebook command and this works, but why? This is because, the jupyter-notebook is stored in usr/local/bin which is normally always stored in the PATH variable.
I then discovered that the jupyter notebook or jupyter --version command will now work if I did the following:
open my ./bash_profile file
add the following to the bottom of the file: export PATH=$PATH:/Users/your-home-directory/Library/Python/3.7/bin
this should add the location of where jupyter is located to your path variable.
Alternatively, as suggested by #HackLab we can also do the following:
python3 -m jupyter notebook
Hopefully, this will give anyone else having the same issues I had an easier time resolving this issue.
I've found a solution from the documentation over at Jupyter https://jupyter-notebook.readthedocs.io/en/stable/troubleshooting.html but I am still curious.
It states that to run the application to use the command jupyter-notebook and hey-presto! It does seem to work now. But, why is this when nearly everywhere else I have read that to run the app we just type the command jupyter notebook.
Also, if I do need to check the version of any of the Jupyter files how do I go about this now, if jupyter --version and notebook --version still don't work.
Also, how do I go about finding these files in my file system if I have no idea where they are located? And how do I go about adding these to my path so that I can, for example, check the version of these programs?
Will pip3 automatically update this software as and when needed?
Thanks again in advance
have you tried locate Jupiter? It may tell you where jupyter is on your system.
Also, why not try installing jupyter via anaconda to avoid the hassle?
I definitely would recommend going through anaconda which makes everything a lot easier.
The following is the link with step by step instructions: https://jupyter.readthedocs.io/en/latest/install.html
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.
I installed Anaconda and can run Python, so I assume that I installed it correctly. Following this introductory documentation, I am trying to install Python v3.3, so I am copying and pasting the following line into my console:
conda create -n py33 python=3.3 anaconda
However, that gives me an error:
-bash: conda: command not found
What do I need to do to run Conda?
I am working on a Linux system.
you might want to try this:
for anaconda 2 :
export PATH=~/anaconda2/bin:$PATH
for anaconda 3 :
export PATH=~/anaconda3/bin:$PATH
for anaconda 4 :
Use the Anaconda Prompt
and then
conda --version
to confirm that it worked.
The export PATH=~/anaconda3/bin:$PATH works but stops when you exit the terminal in order change that you have to run sudo nano ~/.bashrc and then copy the path into the file and save it after that you activate the changes using source .bashrc.
check with conda install anaconda-navigator
if not installed follow the anaconda install instructions again
follow along with this video
https://youtu.be/Pr25JlaXhpc
It turns out that I had not set the path.
To do so, I first had to edit .bash_profile (I downloaded it to my local desktop to do that, I do not know how to text edit a file from linux)
Then add this to .bash_profile:
PATH=$PATH:$HOME/anaconda/bin
Use conda init
As pointed out in a different answer, manually adding Conda on $PATH is no longer recommended as of v4.4.0 (see Release Notes). Furthermore, since Conda v4.6 new functionality to manage shell initialization via the conda init command was introduced. Hence, the updated recommendation is to run
Linux/UNIX (OS X < 10.15)
./anaconda3/bin/conda init
Mac OS X >= 10.15
./anaconda3/bin/conda init zsh
Windows
./anaconda3/Scripts/conda.exe init
You must launch a new shell or source your init file (e.g., source .bashrc) for the changes to take effect.
Details. For an in-depth look at exactly what conda init does see this answer.
Alternative shells
You may need to explicitly identify your shell to Conda. For example, if you run zsh (Mac OS X 10.15+ default) instead of bash then you would run
./anaconda3/bin/conda init zsh
Please see ./anaconda3/bin/conda init --help for a comprehensive list of supported shells.
Word of Caution
I'd recommend running the above command with a --dry-run|-d flag and a verbosity (-v) flag, in order to see exactly what it would do. If you don't already have a Conda-managed section in your shell run commands file (e.g., .bashrc), then this should appear like a straight-forward insertion of some new lines. If it isn't such a straightforward insertion, I'd recommend clearing any previous Conda sections from $PATH and the relevant shell initialization files (e.g., bashrc) first.
Again, for those interested, there is an in-depth look at how it works, in this answer.
Potential Automated Cleanup
Conda v4.6.9 introduced a --reverse flag that automates removing the changes that are inserted by conda init.
If you have installed Anaconda but are not able to load the correct versions of python and ipython, or if you see conda: command not found when trying to use conda, this may be an issue with your PATH environment variable. At the prompt, type:
export PATH=~/anaconda/bin:$PATH
For this example, it is assumed that Anaconda is installed in the default ~/anaconda location.
This info is current as of today, August 10, 2016. Here are the exact steps I took to fix this using methods posted above. I did not see anyone post: export PATH=$PATH:$HOME/anaconda/bin (you need to add export to the beginning of the line).
Here it is, step-by-step:
For anyone running into the same problem while using oh-my-zsh, you need to do the following:
-Open your .zshrc in your terminal. I am using iTerm 2 and have Sublime Text 3 as my default text editor:
subl ~/.zshrc
-Once the file opens in your text editor, scroll to the very bottom and add:
export PATH=$PATH:$HOME/anaconda/bin
-Save the file, then close it.
-Close your terminal, then relaunch it.
-Once back in your terminal, type:
conda --v
You should then see the version of conda installed printed on your screen.
If you're using zsh, then after doing that, your terminal may show you zsh: command not found: rvm-prompt.
The solution is:
add alias rvm-prompt=$HOME/.rvm/bin/rvm-prompt within .zshrc file.
type source .zshrc.
Then the zsh: command not found: rvm-prompt will disappear.
My env: macOS & anaconda3
This works for me:
$ nano ~/.bash_profile
Add this:
export PATH=~/anaconda3/bin:$PATH
*The export path must match with the actual path of anaconda3 in the system.
Exit out and run:
$ source ~/.bash_profile
Then try:
$ jupyter notebook
Edit ~/.bash_profile, add this to it.
PATH=$PATH:$HOME/anaconda/bin
then run
source ~/.bash_profile
Hope can help you.
I'm on High Sierra MAC OS and just installed Anaconda3 via HomeBrew command. I had issue with running :
conda
It'd also give me:
-bash: conda: command not found
I tried running:
export PATH=~/anaconda3/bin:$PATH
but it needs ENTIRE path. so here are the correct steps:
$ nano ~/.bash_profile
Now export the ENTIRE path, in my case it was:
export PATH=/usr/local/anaconda3/bin:$PATH
Exit out and run:
$ source ~/.bash_profile
Then try:
$ conda
it'll output:
$ conda --version
conda 4.4.10
If you have just installed anaconda and got this error, then I think you forgot to run this command :
source ~/.bashrc
This will enable you to make use of anaconda in terminal.
This may seems simple but many (including me) do this mistake.
If the error is still persisting, you have to verify if anaconda location is added to PATH in your system.
Once you add it, you'll be fine
If you have installed Anaconda and have definitely said yes to the:
Do you wish the installer to prepend the Anaconda install location to PATH in your /home/name/.bashrc ? [yes¦no]
question then you maybe just need to restart your terminal window. The change won't take effect until you either (1) close and reopen the current window or (2) just open and start working in a new window
Basically, open a new console window and see if it works now.
For Windows:
A recent Anaconda(version 4.4.0) changed some directories.
You can find "conda" in Anaconda3/Scripts, instead of Anaconda3/bin.
Mostly it is because when we install Anaconda in the end it adds the anaconda path to PATH variable in .bashrc file.
So we just need to restart the terminal or just do
source ~/.bashrc
if still it don't work then follow this commands.
cat >> ~/.bashrc
paste the below command for anaconda3
export PATH=~/anaconda3/bin:$PATH
hit Enter then ctrl+d
source ~/.bashrc
Using the export PATH= strategy with conda activate will result into a warning message for conda>=4.4.
The recommended way (see this release note, and this post) to do is to remove the export PATH=... line and add instead in your .bashrc (.bash_profile) the line:
. ~/anaconda2/etc/profile.d/conda.sh
Furthermore, if you want conda to be activated by default, add:
conda activate
If you have installed anaconda, but if you are not able to execute conda command from terminal, it means the path is not probably set, try :
export PATH=~/anaconda/bin:$PATH
See this link.
I also was facing the same issue ,this might be the simplest possible solution
source anaconda/bin/activate
for anaconda2 use
source anaconda2/bin/activate
depending on the name of the directory , then execute your command i.e. conda --create
Run
cat ~/.bash_profile
to check if anaconda is there. If not you should add its path there.
If conda is there copy the entire row that you see the Anaconda there from "export" to the end of line.
like this:
export PATH=~/anaconda3/bin:$PATH
Run this in your terminal.
Then run
conda --version
to see if it is exported and running!
System: macOS
I installed Anaconda first, and everything worked well. Then I installed iTerm2 and when I typed Python iTerm2 gave me the default Python. Here is how to find your Anaconda Python back:
Open your .zshrc file. For example, vim ~/.zshrc
Then add export PATH="/Users/yourusername/anaconda2/bin:$PATH" to the last line of the file. Note that you need to replace the yourusername to your user name and make sure you have anaconda2. An easy way is to copy this line from ~/.bash_profile
Save the file, close it, relaunch the terminal and now Anaconda Python should be back.
Answer for
Anaconda3 5.2.0 installer
macOS HighSierra
ZSH
Unfortunately, the installer puts the PATH definition only into .bash_profile, but not the .zshrc config.
Contrary to the given answers, it doesn't (necessarily) install in ~/anaconda3/, but instead in /anaconda3/.
The PATHdefintion in .zshrc must therefore be this:
...
# Anaconda3
export PATH="/anaconda3/bin:$PATH"
...
Temporary solution:
$anaconda/bin/conda create -n py33 python=3.3 anaconda
If you have just installed MiniConda or Anaconda make sure you re-run your terminal.
From this, I mean close and open your terminal and then try conda list to verify your installation
For me, this worked!!
To edit bashrc in Ubuntu
$ /usr/bin/vim ~/.bashrc
type PATH=$PATH:$HOME/anaconda3/bin
Press Esc and :wq to save bashrc file and exit vim
enter image description here
then
$ export PATH=~/anaconda3/bin:$PATH
and type $ source ~/.bashrc
Now to confirm the installation of conda type
$ conda --version
Open your terminal and type the following command to add anaconda to environment path
for anaconda 2 :
export PATH=~/anaconda2/bin:$PATH
for anaconda 3 :
export PATH=~/anaconda3/bin:$PATH
Then to check the conda version just type,
conda --version
Create an environment using the following command,
conda create --name myenv
Activate the source using,
source activate myenv
Then your anaconda IDE is ready!!!
If you installed Anaconda with Visual Studio 2017 for Windows,
conda executable is in this path or similar.
In my case path is this:
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\Scripts
Steps to add it to your PATH:
On the Windows desktop, right-click My Computer.
In the pop-up menu, click Properties.
In the System Properties window, click the Advanced tab, and then click Environment Variables.
In the System Variables window, highlight Path, and click Edit.
Add your path and restart your cmd.
You will be able to execute conda
Happy coding!
I am setting up a virtual machine running Ubuntu. I have anaconda 3 installed in the "Home" folder. When I typed "conda" into the terminal I was getting the error "conda: command not found" too.
Typing the code below into the terminal worked for me...
export PATH=$PATH:$HOME/anaconda3/bin
to check it worked I typed:
conda --version
which responded with the version number.
In my case conda Path was properly set (in .bashrc) by the conda installation bash. But to make it works I had to give executable file permissions to files in bin sub folder with chmod +x *.
My system info:
conda 4.2.9
Operating System: Debian GNU/Linux 8 (jessie)
Kernel: Linux 3.16.0-4-amd64
Architecture: x86-64
You need to put Anaconda.sh to your /home/, then run it to install. After that, you can runexport PATH=~/anaconda3/bin:$PATH . Remark: do not run Anaconda.sh in download/ directily!!!!!
I had same issue. What I did, removed anaconda directory from the install location and re-install
after that it worked as I anticipated
First, check the location of anaconda, for me I installed anaconda3 at / directory which I access with /anaconda3
Then in your terminal, input export PATH="<base location>/anaconda3/bin:$PATH" for me it's export PATH="/anaconda3/bin:$PATH".
Finally, input source $/anaconda3/bin/activate. For you, just change to your location.
Now, you could try conda list to test.
Also, visit intallation guide
1. Check where you have installed Anaconda. In my case it looks like /home/nour/anaconda3/bin
Open your .bashrc file. For example $ gedit .bashrc
3. Add this export PATH = /home/nour/anaconda3/bin:$PATH line at the end of the file and save.
Reopen the terminal. Type conda --version
NOTE: Make sure path in line no. 1 and line no. 3 must be same. In my case /home/nour/anaconda3/bin .
The main point is that as of December 2018 it's Scripts not bin.
Updating $PATH in "git bash for windows"
Use one of these:
export PATH=$USERPROFILE/AppData/Local/Continuum/anaconda2/Scripts/:$PATH
export PATH=$USERPROFILE/AppData/Local/Continuum/anaconda3/Scripts/:$PATH
Updating $PATH in the windows default command line
Use one of these:
SET PATH=%USERPROFILE%\AppData\Local\Continuum\anaconda2\Scripts\;%PATH%
SET PATH=%USERPROFILE%\AppData\Local\Continuum\anaconda3\Scripts\;%PATH%
Updating $PATH in Linux
Change /app to your installation location. If you installed anaconda change Miniconda to Anaconda. Also, check for Script vs. bin,.
export PATH="/app/Miniconda/bin:$PATH"
You may need to run set -a before setting the path, I think this is important if you're setting the path in a script. For example if you have your export command in a file called set_my_path.sh, I think you'd need to do set -a; source("set_my_path.sh").
The set -a will make your changes to the path persist for your session, but they are still not permanent.
For a more permanent solution add the command to ~/.bashrc. The installers may offer to add something like this to your ~/.bashrc file, but you can do it too (or comment it out to undo it).
General Observations:
Background: I installed the 64 bit versions of Anaconda 2 and 3 recently on my Windows 10 machine following the recommended installation steps in December of 2018.
Adding conda also enables ipython, which works much better in the native Windows command line
Following the strongly recommended installation does not add conda or ipython to the path
Anaconda 3 doesn't seem to install a command prompt application, but Anaconda 2 did have a command prompt application
The /bin folder seems to have been replaced with Scripts
Poking around in the Scripts folder is interesting, maybe the Anaconda command prompt application is in there somewhere.