How to add another path to the Python Path on AWS SageMaker - python

I've been trying to add one of my folders where I hold my python modules and, so far, I haven't been able to do it through AWS's terminal. The folder with the .py files is inside the main SageMaker folder, so I'm trying (I've also tried it with SageMaker/zds, which is the folder that holds the modules):
export PYTHONPATH="${PYTHONPATH}:SageMaker/"
After printing the directories of the PYTHONPATH through the terminal with python -c "import sys; print('\n'.join(sys.path))", I get that indeed my new path is included in the PYTHONPATH. However, when I try to import any module from any notebook (with from zds.module import * or from module import *), I get the error that the module doesn't exist. If I print the paths from the PYTHONPATH directly inside the notebook I no longer see the previously added path in the list.
Am I missing something basic here or is it not possible to add paths to the PYTHONPATH inside AWS SageMaker? For now, I'm having to use import sys, os
sys.path.insert(0, os.path.abspath('..')) inside basically every notebook as a fix to the problem.

Adding this to the lifecycle script worked for me
sudo -i <<'EOF'
touch /etc/profile.d/jupyter-env.sh
echo export PYTHONPATH="$PYTHONPATH:/home/ec2-user/SageMaker/repo-name/src" >> /etc/profile.d/jupyter-env.sh
EOF

Thanks for using Amazon SageMaker!
Copying from the https://docs.aws.amazon.com/sagemaker/latest/dg/notebook-lifecycle-config.html
Amazon SageMaker notebook instances use conda environments to implement different kernels for Jupyter notebooks. If you want to install packages that are available to one or more notebook kernels, enclose the commands to install the packages with conda environment commands that activate the conda environment that contains the kernel where you want to install the package
For example, if you want to install a package only in for the python3 environment, use the following code:
# This will affect only the Jupyter kernel called "conda_python3".
source activate python3
# Replace myPackage with the name of the package you want to install.
pip install myPackage
# You can also perform "conda install" here as well.
source deactivate
If you do installation in above suggested way you should be able to import your package from the Notebook corresponding Kernel which you are using. Let us know if it doesn't help.

Related

Import module could not be resolved

I've successfully installed "PyPDF2" module and checked it using the command 'pip list'.
yet when I try to import it i receive this message:
'''Import "PyPDF2" could not be resolved'''
The version of python that you installed the module in and the version that your IDE is using might be different check what version you installed it in by typing
pip -VV
in your terminal and check in what version your IDE is using (for vs code its usually shown at the bottom left or can be seen in the command pallete by typing Python: Select Interpreter)
another reason this could happen is if you are using an IDE like pycharm which by default creates a virtual environment for each project in which case you would need to either install your module from pycharm's terminal or activate the virtual environment and then install in it (docs here show how to https://docs.python.org/3/tutorial/venv.html)
Make sure you have installed PyPDF2
pip install PyPDF2
Select the correct interpreter
Click
First of all, please make sure that you are using the correct environment and python interpreter. If multiple python versions exist on your computer, use the command to install the PyPDF2 package under the version you need. For example python3:
py -3 -m pip install PyPDF2
Another possible reason: Paths are not imported correctly. Please add the following commands in the setting.json file:
"python.analysis.extraPaths":[
// The folder path where the custom module is located, and multiple paths can be added (the following is just an example)
// absolute path
"c:\\workspace\\pythontest\\.venv\\lib\\site-packages",
"E:\\myfolder\\homework\\one\\Person_reID_baseline_pytorch-master",
// relative path
"./src",
"./modules"
]

Tensorflow Object Detection API on Windows - error "ModuleNotFoundError: No module named 'utils'"

I'm attempting to get the TensorFlow Object Detection API
https://github.com/tensorflow/models/tree/master/research/object_detection
working on Windows by following the install instructions
https://github.com/tensorflow/models/tree/master/research/object_detection
Which seem to be for Linux/Mac. I can only get this to work if I put a script in the directory I cloned the above repo to. If I put the script in any other directory I get this error:
ModuleNotFoundError: No module named 'utils'
I suspect that the cause is not properly doing the Windows equivalent of this command listed on the install instructions above:
# From tensorflow/models/research/
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
I'm using Windows 10, Python 3.6, and TensorFlow 1.4.0 if that matters. Of course, I've Googled on this concern and found various links, for example, this:
https://github.com/tensorflow/models/issues/1747
But this has not resolved the concern. Any suggestions on how to resolve this?
Here are the steps I've done so far specifically:
EDIT: these steps work now after updating to incorporate RecencyEffect's answer
1) Install TensorFlow and related tools via pip3
2) From an administrative command prompt, run the following:
pip3 install pillow
pip3 install lxml
pip3 install jupyter
pip3 install matplotlib
3) Clone the TensorFlow "models" repository to the Documents folder, in my case
C:\Users\cdahms\Documents\models
4) Downloaded Google Protobuf https://github.com/google/protobuf Windows v3.4.0 release "protoc-3.4.0-win32.zip" (I tried the most current 3.5.1 and got errors on the subsequent steps, so I tried 3.4.0 per this vid https://www.youtube.com/watch?v=COlbP62-B-U&list=PLQVvvaa0QuDcNK5GeCQnxYnSSaar2tpku&index=1 and the protobuf compile worked)
5) Extract the Protobuf download to Program Files, specifically
"C:\Program Files\protoc-3.4.0-win32"
6) CD into the models\research directory, specifically
cd C:\Users\cdahms\Documents\models\research
7) Executed the protobuf compile, specifically
“C:\Program Files\protoc-3.4.0-win32\bin\protoc.exe” object_detection/protos/*.proto --python_out=.
Navigate to:
C:\Users\cdahms\Documents\models\research\object_detection\protos
and verify the .py files were created successfully as a result of the compile (only the .proto files were there to begin with)
8) cd to the object_detection directory, ex:
cd C:\Users\cdahms\Documents\models\research\object_detection
then enter the following at a command prompt to start the object_detection_tutorial.ipynb Jupyter Notebook
jupyter notebook
9) In the Jupyter Notebook, choose "object_detection_tutorial.ipynb" -> Cell -> Run all, the example should run within the notebook
10) In the Jupyter Notebook, choose “File” -> “Download As” -> “Python”, and save the .py version of the notebook to the same directory, i.e.
C:\Users\cdahms\Documents\models\research\object_detection\object_detection_tutorial.py
You can now open the script in your chosen Python editor (ex. PyCharm) and run it.
EDIT per RecencyEffect's answer below, if you follow these additional steps you will be able to run the object_detection_tutorial.py script from any directory
11) Move the script to any other directory, then attempt to run it and you will find you will get the error:
ModuleNotFoundError: No module named 'utils'
because we have not yet informed Python how to find the utils directory that these lines use:
from utils import label_map_util
from utils import visualization_utils as vis_util
To resolve this . . .
12) Go to System -> Advanced system settings -> Environment Variables . . . -> New, and add a variable with the name PYTHONPATH and these values:
13) Also under Environment Variables, edit PATH and add %PYTHONPATH% like so:
14) Reboot to make sure these path changes take effect
15) Pull up a command prompt and run the command "set", verify PYTHONPATH is there and PYTHONPATH and PATH contained the values from the previous steps.
16) Now you can copy the "object_detection_tutorial.py" to any other directory and it will run
As mentioned in the comment, utils is a submodule so you actually need to add object_detection to PYTHONPATH, not object_detection/utils.
I'm glad it worked for you.
cd Research/Object_Detection
cd ..
Research
export PATH=~/anaconda3/bin:$PATH
RESEARCH
git clone https://github.com/tensorflow/models.git
RESEARCH
3.export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim
4.protoc object_detection/protos/string_int_label_map.proto --python_out=.
CD OBJECT_DETECTION
protoc protos/string_int_label_map.proto --python_out=.
6.jupyter notebook
The following command does not work on Windows:
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
Instead, I followed the directions of this tutorial, which recommends setting the path variables for three different directories manually. I simply added a path for the utils directory as well. So far it has worked without error.
Make sure you have a __init__.py file in your research/object_detection/protos folder! The __init__.py file is empty but needs to exist for the protos module to be created correctly.

Module Not found during import in Jupyter Notebook

I have the following package (and working directory):
WorkingDirectory--
|--MyPackage--
| |--__init__.py
| |--module1.py
| |--module2.py
|
|--notebook.ipynb
In __init__.py I have:
import module1
import module2
If I try to import MyPackage into my notebook:
import MyPackage as mp
I will get ModuleNotFoundError: No module named 'module1'. But import works fine if I execute the script outside a notebook: if I create test.py in the same directory and do the same as in the notebook the import would work properly. It will work inside the notebook if I use fully qualified name in __init__.py (import MyPackage.module1).
What's the reason for different import behavior?
I have confirmed the working directory of the notebook is WorkingDirectory.
---Update---------
Exact error is:
C:\Users\Me\Documents\Working Directory\MyPackage\__init__.py in <module>()
---> 17 import module1
ModuleNotFoundError: No module named 'module1'
My problem differs from the possible duplicate:
The notebook was able to find the package, but only unable to load the module. This was inferred from substituting module1 with MyPackage.module1 worked well and suggests it may not be a problem related with PATH.
I cded into WorkingDirectory and started the server there. The working directory should be the folder containing my package.
I'm pretty sure this issue is related and the answer there will help you: https://stackoverflow.com/a/15622021/7458681
tl;dr the cwd of the notebook server is always the base path where you started the server, no matter was running import os os.getcwd() says. Use import sys sys.path.append("/path/to/your/module/folder").
I ran it with some dummy modules in the same structure as you had specified, and before modifying sys.path it wouldn't run and after it would
understand this two functions, your problem will be solved.
#list the current work dir
os.getcwd()
#change the current work dir
os.chdir()
change the path, and import module, have fun.
sometime it won't work.try this
import sys
# sys.path is a list of absolute path strings
sys.path.append('/path/to/application/app/folder')
import file
-, -
if you face module not found on jupyter environment you had to install it on jupyter environment instead of installing it on command prompt
by this command(for windows) on jupyter
!pip install module name
after that you can easily import and use it.
Whenever you want to tell jupyter that this is system command you should put ( ! ) before your command.
The best way to tackle this issue is to create a virtual env and point your kernel to that virtual environment:
Steps:
python -m venv venv
source venv/bin/activate
ipython kernel install --user --name=venv
jupyter lab
go to the jupyter lab ->kernel-->change kernel-->add the venv from the dropdown
Now if your venv has the package installed, jupyter lab can also see the package and will have no problem importing the package.
You can do that by installing the import_ipynb package.
pip install import_ipynb
Suppose you want to import B.ipynb in A.ipynb, you can do as follows:
In A.ipynb:
import import_ipynb
import B as b
Then you may use all the functions of B.ipynb in A.
My problem was that I used the wrong conda enviroment when using Vs Code.
Enter your conda enviroment
conda activate **enviroment_name**
To check where a module is installed you can enter python interactive mode by writing python or python3. Then importing cv2
import cv2
Then to see where this module is installed
print(cv2.__file__)
You will see the installed path of the module. My problem was that my vs code kernel was set to the wrong enviroment. This can be changed in the top right corner for vs code.
hope this helps
this happened to me when I moved my journal into a new directory while the Jupyter lab server was running. The import broke for that journal, but when I made a new journal in the same directory I just moved to and used the same import, it worked. To fix this I:
Went to the root dir for my project.
Searched for all folders labeled “pycache”
Deleted all “pycache” folders that were found in my root and subfolders.
Restarted Jupyter lab server
Once Jupyter lab restarts and compiles your code, the “pycache” folders will be regenerated. Also the pycache folders have two leading and trailing “_”, but stackoverflow is formatting the pycache’s without them
The best solution by far (for me) is to have a kernel for each environment you are working in. Then, with that kernel defined, all you have to do is to update this kernel's environment variables to look at your project folder where your modules are located.
Steps (using pip):
pip install ipykernel (if not installed already)
source activate <your environment name>
python -m ipykernel install --user --name <your environment name> --display-name "<a display name>" (where is the name you want to give to your kernel and is just a name used for display by jupyter.
Once you ran the command above, it will output the location of the kernel configuration files. E.g.: C:\Users\<your user name>\AppData\Roaming\jupyter\kernels\<selected environment name>. Go to this folder and open the kernel.json file.
Add the following entry to this file:
"env": {
"PYTHONPATH": "${PYTHONPATH};<the path to your project with your modules>
}
Good reference about the kernel install command here.
The reason is that your MyPackage/__init__.py is ran from the current working directory. E.g. from WorkingDirectory in this case. It means, that interpreter cannot find the module named module1 since it is not located in either current or global packages directory.
There are few workarounds for this. For example, you can temporarily override a current working directory like this
cwd = os.getcwd()
csd = __path__[0]
os.chdir(csd)
and then, after all a package initialization actions like import module1 are done, restore "caller's" working directory with os.chdir(cwd).
This is quite a bad approach as for me, since, for example, if an exception is raised on initialization actions, a working directory would not be restored. You'll need to play with try..except statements to fix this.
Another approach would be using relative imports. Refer to the documentation for more details.
Here is an example of MyPackage/__init__.py that will work for your example:
from .module1 import *
But it has few disadvantages that are found rather empirically then through the documentation. For example, you cannot write something like import .module1.
Upd:
I've found this exception to be raised even if import MyPackage is ran from usual python console. Not from IPython or Jupyter Notebook. So this seems to be not an IPython itself issue.

Running Jupyter via command line on Windows

I have installed Jupyter on Windows 10, Python 3.x via
$ pip install jupyter
The installation works fine, even though I did restart the terminal.
But trying to run
$ jupyter notebook
gives the following error
'jupyter' is not recognized as an internal or external command, operable program or batch file.
How and where do I find the executable for Jupyter?
If you are absolutely sure that your Python library path is in your system variables (and you can find that path when you pip install Jupyter, you just have to read a bit) and you still experience "command not found or recognized" errors in Windows, you can try:
python -m notebook
For my Windows at least (Windows 10 Pro), having the python -m is the only way I can run my Python packages from command line without running into some sort of error
Fatal error in launcher: Unable to create process using ' "
or
Errno 'THIS_PROGRAM' not found
Please try either of these commands first;
$ py -m notebook
$ python -m notebook
for jupyterlab users
py -m jupyterlab
Otherwise
$ python -m pip install jupyter --user
$ jupyter notebook
If this does not work.
pip does not add jupyter directly to path for local.
The output from
$ which python
/c/Users/<username>/AppData/Local/Programs/Python/Python35-32/python
After some digging I found a executable for jupyter in the folder:
C:\Users\<username>\AppData\Roaming\Python\Python35\Scripts\jupyter.exe
Difference between local and roaming folder
So if you want to be able to execute a program via command line, you need to add it into the %PATH variable. Here is a powershell script to do it. BE SURE TO ADD THE ";" before adding the new path.
$ [Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Users\<username>\AppData\Roaming\Python\Python35\Scripts", [EnvironmentVariableTarget]::User)
Update:
if you are using python3, switch out python with python3
but I encourage you to use pyenv instead :)
I had the exact same problem and it was driving me crazy. Other answers provide a solution, but they don't explain why you and I are having this problem.
I will try to explain why this is happening and then provide some solutions.
You can go to the end to see the TL;DR.
1)What's going on? Why is this error happening?
I'll try to make a step-by-step answer so everything is explained clearly.
If you think it's too basic at the beginning, go to the end of this "article".
I'll first start with common things like running the python shell from the terminal or running pip. You'll see why you can do that from the terminal and we'll end up on why and how you can run the jupyter notebook from the terminal as well.
Ready? Let's start!
Have you ever wondered why you can type python in the terminal (command prompt) and suddenly start the Python interpreter?
Microsoft Windows [Version 10.0.18363.1440]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\Users\YOUR-USERNAME>python
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
You probably already know (but maybe don't) that this is because Python was added to the Windows PATH environment variable. You probably did it at installation time or afterwards.
But, what is this PATH environment variable?
It basically allows you to run any executables, that are located inside
the paths specified in the variable, at the command prompt without
having to give the full path to the executable.
You can check the content of that PATH variable with:
>>> import sys
>>> for path in sys.path:
print(path)
C:\Users\YOUR-USERNAME\AppData\Local\Programs\Python\Python39\python39.zip
C:\Users\YOUR-USERNAME\AppData\Local\Programs\Python\Python39\DLLs
C:\Users\YOUR-USERNAME\AppData\Local\Programs\Python\Python39\lib
C:\Users\YOUR-USERNAME\AppData\Local\Programs\Python\Python39
C:\Users\YOUR-USERNAME\AppData\Local\Programs\Python\Python39\lib\site-packages
... (some other paths were taken out for clarity)
You can see this folder: C:\Users\YOUR-USERNAME\AppData\Local\Programs\Python\Python39. This is the place where Python version 3.9 is installed. Let's check its content:
<DIR> DLLs
<DIR> Doc
<DIR> etc
<DIR> include
<DIR> Lib
<DIR> libs
<DIR> Scripts
<DIR> share
<DIR> tcl
<DIR> Tools
LICENSE.txt
NEWS.txt
python.exe
python3.dll
python39.dll
pythonw.exe
vcruntime140.dll
vcruntime140_1.dll
Voilà! We have the python.exe file (an executable). We have a Python executable file in the PATH, that's why you can start the Python interpreter from the terminal with just typing python. If this wasn't the case you would have to type the full path to the executable file in the terminal:
C:\Users\YOUR-USERNAME> C:\Users\YOUR-USERNAME\AppData\Local\Programs\Python\Python39\python)
Instead of just:
C:\Users\YOUR-USERNAME> python
And what about when you use pip?
It's the same principle. You can run pip from the terminal because there is a pip executable file in the PATH variable.
If you go to C:\Users\YOUR-USERNAME\AppData\Local\Programs\Python\Python39\Scripts\ (which is in the PATH showed above) you'll see many executables files. One of them is pip. Actually I have three versions: pip, pip3.9 and pip3.
The Scripts folder allows exectuable files to be run from the terminal. Like pip or other libraries that you intend to run directly from the terminal. The Scripts folder:
...is not intended for you, it's for scripts that are installed as
components of modules that you install. For example, pip is a module,
but it also has a wrapper script by the same name, pip, which will be
installed in that directory.
If you put something there and it is properly in your PATH, then it
should be executable
That wrapper script would be the pip executable file. When this executable file is run, it locates the pip folder in the Python installation folder and runs pip.
But you could also run pip directly from the installation folder (C:\Users\YOUR-USERNAME\AppData\Local\Programs\Python\Python39\Lib\site-packages), without needing the executable pip file.
But, how can you do it?
I'm glad you ask. There is a Python way to run modules as the main module (without the need to import it).
python -m pip
When you run a module directly its name becomes __main__. What -m does is:
Search sys.path for the named module and execute its contents as the __main__ module.
What is __main__?
'__main__' is the name of the scope in which top-level code executes.
A module’s __name__ is set equal to '__main__' when read from standard
input, a script, or from an interactive prompt.
...
I guess that the pip executable does something similar, or at least, has the same effect: to start pip.
2)What does this have to do with the Jupyter Notebook?!
Think of the Jupyter Notebook as the same as pip. If you want to run jupyter in the terminal, you need an executable that it's on the PATH.
We have already seen that the executables of modules like pip or jupyter are located here C:\Users\YOUR-USERNAME\AppData\Local\Programs\Python\Python39\Scripts\.
If I check the content of the folder I see this:
easy_install-3.9.exe
easy_install.exe
f2py.exe
jsonschema.exe
jupyter-bundlerextension.exe
jupyter-console.exe
jupyter-nbconvert.exe
jupyter-nbextension.exe
jupyter-notebook.exe
jupyter-qtconsole.exe
jupyter-serverextension.exe
jupyter-trust.exe
pip.exe
pip3.9.exe
pip3.exe
I see the already mentioned pip, pip3.9 and pip3. But I don't see jupyter (the word "jupyter" alone).
If I type jupyter in the terminal I get the error that started all:
'jupyter' is not recognized as an internal or external command, operable program or batch file.
Finally we've reached an answer to your question!!!
'jupyter' is not recognized as a command because there is no executable file in the Scripts folder called jupyter.
So, let's try a different executable. What about jupyter-notebook?
BINGO! The notebook is running!
Serving notebooks from local directory:
C:\Users\YOUR-USERNAME\AppData\Local\Programs\Python\Python39\Scripts
Jupyter Notebook 6.3.0 is running at:
http://localhost:8888/?token=... (edited)
or http://127.0.0.1:8888/?token=... (edited)
Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
I don't know why I don't have a jupyter executable called 'jupyter'. The official documentation says to use jupyter notebook on the terminal, but it seems that in some cases it doesn't work. And I think it has to do with what I mentioned above: there is no jupyter exectuable in the Scripts folder.
If you remember, I told you that you can run pip as the main module using python -m pip.
It happens that you can do the same with jupyter.We just need to know how to call it. As in with pip, we have to check the folder where 3rd party libraries are installed: C:\Users\YOUR-USERNAME\AppData\Local\Programs\Python\Python39\Lib\site-packages.
You'll see jupyter_console, but this just creates an interactive notebook in the terminal, not exactly what you were looking for. You're also going to find folders ending with .dist.info, like jupyter_console-6.4.0.dist-info. This is just metadata of the Wheel Binary Package builder. You'll also see a folder like jupyterlab_pygments, but that's for JupyterLab. We want to use the classic Jupyter notebook.
What we want is to run notebook. How do we know this?
You'll see in the folder site-packages the folder (package) notebook. Inside there is a file called __main__.py:
#__main__.py
if __name__ == '__main__':
from notebook import notebookapp as app
app.launch_new_instance()
It's calling notebookapp.py which is a "A tornado based Jupyter notebook server." Yes, this is what we need.
We can see that launch_new_instance in the notebookapp calls launch_instance(), which "launches an instance of a Jupyter Application".
Perfect! We are in the correct folder. To run the jupyter notebook from the Python interactive shell we have to run the notebook package with:
python -m notebook
3)*** SUMMARY: SOLUTION ***
tl;dr:
I have explained and showed why this error is happening.
Now let's summarize the solutions:
To know the name of the jupyter executable (in the Scripts folder), so you can run directly from the terminal (Command Prompt) as:
jupyter notebook
or as:
jupyter-notebook
Or whatever name you have.
Run the notebook as the main module from Python:
python -m notebook
I hope this helps you as much as it helped me. I'm open to your comments and suggestions.
I had the same problem, but
py -m notebook
worked for me.
I got Jupyter notebook running in Windows 10. I found the easiest way to accomplish this task without relying upon a distro like Anaconda was to use Cygwin.
In Cygwin install python2, python2-devel, python2-numpy, python2-pip, tcl, tcl-devel, (I have included a image below of all packages I installed) and any other python packages you want that are available. This is by far the easiest option.
Then run this command to just install jupyter notebook:
python -m pip install jupyter
Below is the actual commands I ran to add more libraries just in case others need this list too:
python -m pip install scipy
python -m pip install scikit-learn
python -m pip install sklearn
python -m pip install pandas
python -m pip install matplotlib
python -m pip install jupyter
If any of the above commands fail do not worry the solution is pretty simple most of the time. What you do is look at the build failure for whatever missing package / library.
Say it is showing a missing pyzmq then close Cygwin, re-open the installer, get to the package list screen, show "full" for all, then search for the name like zmq and install those libraries and re-try the above commands.
Using this approach it was fairly simple to eventually work through all the missing dependencies successfully.
Cygwin package list
Once everything is installed then run in Cygwin goto the folder you want to be the "root" for the notebook ui tree and type:
jupyter notebook
This will start up the notebook and show some output like below:
$ jupyter notebook
[I 19:05:30.459 NotebookApp] Serving notebooks from local directory:
[I 19:05:30.459 NotebookApp] 0 active kernels
[I 19:05:30.459 NotebookApp] The Jupyter Notebook is running at:
[I 19:05:30.459 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
Copy/paste this URL into your browser when you connect for the first time, to login with a token:
http://localhost:8888/?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
In Python 3.7.6 for Windows 10. After installation, I use these commands.
1. pip install notebook
2. python -m notebook
OR
C:\Users\Hamza\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\Scripts
.
For my pc python-scripts are located in the above path. You can add this path in environment variables. Then run command.
1. jupyter notebook
You can add the following to your path
C:\[Python Installation path]\Scripts
e.g. C:\Python27\Scripts
It will start working for jupyter and every other pip install you will do here on.
Check whether you have given python PATH in environmental variables properly.
If not, then set python path. Then use:
$ python -m notebook
If you are using the Anaconda distribution, make sure when installing it that you check the "Change PATH" option.
first you should make sure that you are put your python path in your system variables ..
Then try run this
python -m pip install jupyter --user
and then
run this
py -m notebook or jupyter notebook
In Windows 10 you can use ipython notebook. It works for me.
I added
c:\users\[user]\appdata\roaming\python\python37\site-packages
to the path and it worked.
## windows CMD
for default install (just check "add path" and "next" when installing)
python -m notebook
for custom install in C:\
jupyter notebook
Problem for me was that I was running the jupyter command from the wrong directory.
Once I navigated to the path containing the script, everything worked.
Path-
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\Scripts
I have two python version installed:
1. Python 3.8.2: This was installed independently
2. Python 3.7.6: This was installed along with Anaconda 3
Multiple versions caused conflict even after setting the path variables correctly.
I have uninstalled the Python 3.8.2 and after restart, the command
jupyter notebook
Worked perfectly :)
you can create a batch file and search for Jupiter in your windows search and ooen its properties and you will get this string.
D:\anaconda3\python.exe D:\anaconda3\cwp.py D:\anaconda3 D:\anaconda3\python.exe D:\anaconda3\Scripts\jupyter-notebook-script.py "%USERPROFILE%/"
after getting this you can create a jupitor.bat file with this content it that
and you can save that file in a script folder in d or any drive and add the path of your script file in your environmental path
and then you can easly call this by typing jupitor in cmd.
To install I used
"pip install notebook" in windows command line
To run python -m notebook did not work for me, but python3 -m notebook worked
First run this command
pip install jupyter
then add system variable path , this path is where jupyter and other scripts are located
PATH = C:\Users<userName>\AppData\Roaming\Python\Python38\Scripts
e.g PATH=C:\Users\HP\AppData\Roaming\Python\Python38\Scripts
After that we can run jupyter from any folder/directory
jupyter notebook
I just found that error when I first intalled and run the jupyter notebook. Then I found the executable (.exe) file from
C:\Users\<user-name>\AppData\Local\Programs\Python\Python39\Scripts.
The actual file name was "jupyter-notebook".
The installation guide says it as "jupyter notebook" to run the server. You have to run the command "jupyter-notebook" in the command line and it will be run. Thanks!
My problem was my user's folder had a space in folder name.
After creating a new user and switching to that windows user, windows shortcuts and links from within' Anaconda worked fine.
Windows 8.1 64 Bit. Latest Anaconda.
Note: I ended up uninstalling an reinstalling Anaconda but my sense is the problem was really just the space in the windows user username/user folder.
Using python 3.6.3. Here after installing Jupyter through command 'python -m pip install jupyter', 'jupyter notebook' command didn't work for me using windows command prompt.
But, finally 'python -m notebook' did work and made jupyter notebook to run on local.
http://localhost:8888/tree
Here is how I resolved stated issue, hope it helps:
install python 3.7 using official website for python, while installing include installing PATH by checking it's box
after that open cmd (be sure to open it after step 1) and write: pip install jupyter ENTER
now you should be able to open jupyter notebook by using command: jupyter notebook
Seems simple, but it may as well help.
In windows 10:
If you used anaconda3 for Jupyter notebook installation and forgot to check the box to add the environment variables to the system during installation, you need to add the following environment variables to the "Path" variable manually:
(search windows settings for Edit environment variables")
Environment variables for Anaconda3
If you have installed jupyter with
"python -m pip install jupyter" command
instead of
"$ pip install jupyter" command
then follow these steps:
Create a notepad
Change its extension from ".txt" to ".ipynb"
Right click it and click "open with"
In the pop up, go to - C:\Users\<"windows_user_name">\AppData\Roaming\Python\Python38\Scripts
Click on "jupyter-lab.exe"
100% working solution:
Follow these steps:
Open the folder where you downloaded "python-3.8.2-amd64.exe" setup or any other version of python package
Double click on "python-3.8.2-amd64.exe'
Click "Modify"
You will see "Optional features"
Click "next"
Select "Add python to environment variables"
Click "install"
Then u can run jupyter in any desired folder u desire
E.g open "cmd" command prompt
Type :
E:
E:\>jupyter notebook
It will get started without showing
'Jupyter' is not recognized
Thanks
I was facing the same issue in windows7, as i just recoverd my computer with the help of recovery point and after that notebook just stopped working. I tried to change the path setting but nothing was working so I just simply uninstalled the python with the application from which it was installed and after that I installed it again. After that I installed jupyter notebook again and then it worked fine.
Thanks
I just installed JupyterLab on top of my Python 3.8/pip enabled Win10 machine, so I ran into these startup problem with windows.
If everything is ok (check that you have PATH for Python, eg. C:\Users[Username]\AppData\Local\Programs\Python\Python38-32\Scripts) you simply run:
jupyter-lab.exe
and that's it.
Cheers
Add system variable path, this path is where jupyter and other scripts are located
PATH -->
`C:\Users\<userName>\AppData\Roaming\Python\Python39\Scripts`
Like in my laptop PATH is:
"C:\Users\developer\AppData\Roaming\Python\Python39\Scripts"
After that, You will be able to run jupyter from any folder & any directory by running the below command
jupyter notebook
Had the same issue. Finally searched where jupyter.exe directory was located on my computer. For some reason it was under
C:\VTRoot\HarddiskVolume4\Users[user]\AppData\Local\Programs\Python
Whereas the Python is
C:\Users[user]\AppData\Local\Programs\Python
So I copied full Python39 folder from VTRoot to main Python39 python folder in AppData. And the issue is solved.
First check where your python is installed by heading over to
C:\Users\**username**\AppData\Local\Programs\Python\Python39\Scripts
this is the path usually you will find python installed. After this type in
cd.. to get one step out of the Scripts folder
After this install jupyter in here using:
$ pip install jupyter
The installation was fine and when I tried to open the jupyter notebook, it gave me the following error.
'jupiter is not recognized as an internal or external command, operable program or batch file.
I checked a lot of resources but still, I faced the same problem. After doing a lot of stuff from the internet, I myself figured out that maybe due to some updates(for some users) it won't open by typing the command
jupyter notebook
Instead, you have to type
jupyter-notebook
The only thing I was missing was this Hyphen-minus. Hope this works for you too.

create module for python package

I have recently installed kmos, a python package using pip in my user account on my institute cluster. How to create a module for kmos and set the path to the directory such that python accesses the library. Currently, I am giving the path to the kmos binary while running the program.
Linux distro: Cent OS
Module support: Lua-based Lmod environmental modules system
I am not exactly sure what you mean by "How to create a module for kmos". You didn't mention which terminal you are using. However it will be definitely helpful to understand the mechanism behind finding executables and python import.
If you want to execute the kmos command-line interface (e.g. kmos export ...) you need to make sure that wherever the kmos shell client is is in your $PATH variable. When you installed kmos (pip install --user --upgrade kmos) it should tell where it went. That directory needs to show up when you run echo $PATH. Most likely something like ~/.local/bin. If it doesn't show up you may want to put export PATH=${PATH}:~/.local/bin into your ~/.bashrc or the corresponding syntax in your echo $SHELL configuration file.
The other location is where the python module gets copied to. When you do the pip installation it should print this out as well. Most likely something like ~/.local/lib/pythonXY/site-packages. When you run python -c "import sys; print(sys.path)" it should include given directory. You can automatically add this directory again using your echo ${SHELL} configuration file like export PYTHONPATH=${PYTHONPATH}:~/.local/lib/pythonXY/site-packages.
If you can already import kmos from python then python -c "import kmos; print(kmos.__file__)" will tell you where it found it.

Categories