How to open ipynb files on a Mac? - python

How to open an .ipynb file on a Mac and use it?
Which apps is needed for that or what are your recommendations?

you need to install jupyter you can do it using: pip install jupyter
and run it in terminal with the command jupyter notebook this will open a browser window where you can view and run juputer notebooks
You can also open these notebooks in pyCharm and Visual Studio Code (after installing the python extension from microsoft)

You tagged this with visual-studio-code so I'm answering in the context of Visual Studio Code.
VS Code has support for creating, opening/viewing, and running Jupyter notebooks (.ipynb files). Check out their complete tutorial from the VS Code docs: Working with Jupyter Notebooks in Visual Studio Code.
Visual Studio Code supports working with Jupyter Notebooks natively,
as well as through Python code files. This topic covers the native
support available for Jupyter Notebooks and demonstrates how to:
Create, open, and save Jupyter Notebooks
Work with Jupyter code cells
View, inspect, and filter variables using the Variable explorer and Data viewer
Connect to a remote Jupyter server
Debug a Jupyter notebook
If you just want to view/open a .ipynb file, just open it in VS Code like any other file.
If it doesn't open like that and you get a "weird" JSON-like file, make sure the setting "Jupyter: Use Notebook Editor" is enabled.
"jupyter.useNotebookEditor": true
If you need to be running cells, you'll need to setup your environment and install the Jupyter package.
You can let VS Code do all the initial setup steps for you. Open or create a .ipynb file, and try to run any cell. If your environment is not yet setup, it will show an error:
So click on that Install button to let VS Code install all the dependencies on the currently selected Python environment.
Or if you want to install it yourself, select and activate an environment, then:
$ pip install jupyter
Once the Jupyter package is now installed, you'll see that the "Jupyter Server" indicator at the top right is now activate. Now, you can run cells.
So basically, all you need to do is:
Install VS Code
Setup a Python environment
On mac OS, it already has Python 2 but I recommend not using that
Instead, I recommend installing Python 3 via Homebrew
Install the Jupyter package
Select the Python environment (with the Jupyter package)
Open and edit .ipynb files

To quickly view an .ipynb file you can use the nbviewer-app.
Installation via Homebrew:
$ brew install --cask jupyter-notebook-viewer
Alternatively, you can also download the app directly.
Starting with Mac OS Catalina, you might have to open a terminal and run
xattr -d com.apple.quarantine /Applications/Jupyter\ Notebook\ Viewer.app
after installation because the app is not notarized by Apple [Source].

Related

Facing problem in Exporting a ipynb file to pdf in VS Code

I have fulfilled all the requirements for exporting a jupyter notebook (ipynb) to pdf in VScode but still, it gives me the same error of installing TeX, Although
I have MiKTex installed in my system
I have Installed TeX package
I have Pandoc installed in my system.
When I installed MiKTeX and TeX it was not working but when I installed Pandoc it just worked once but now it giving me the same error.
This is how I have installed the dependencies:
I have installed nbconvert through this command pip install nbconvert.
For TeX pip install tex
For pandoc i downloaded an .exe file from their website and installed it in my system, besides this I also installed pandoc package through this command in terminal pip install pandoc
However I still have an error:
error 13:11:2.772: If you have not installed xelatex (TeX) you will
need to do so before you can export to PDF, for further instructions
please look
nbconvert.readthedocs.io/en/latest/install.html#installing-tex. To
avoid installing xelatex (TeX) you might want to try exporting to HTML
and using your browsers "Print to PDF" feature.
Kindly Help me in this regard TIA.
Open the jupyter file with Chrome and convert it to PDF by printing. This way is simpler and more effective.
UPDATE:
First make sure that the path environment variable of Tex already exists in your machine
Then run vscode with admin
Use the following command in the terminal (or the terminal where the virtual environment is activated if using a virtual environment) to export the PDF
# Remember to replace your_notebook with your filename
jupyter nbconvert your_notebook.ipynb --to pdf
During the execution of the command, many such pop-up windows may pop up prompting you to install files, please select "Install"
Sorry for the Chinese interface
After the command is executed, a PDF file will be generated in the same directory as your jupyter file.
After that you can run vscode without administrator and export PDF. Also, the interfaced export can also be used.
The installation of MiKTeX and TeX depends on the operating system.
If you are using Linux try executing the following code inside the terminal of your environment:
apt-get install texlive-xetex texlive-fonts-recommended texlive-plain-generic
If you are using Windows you should get the MiKTeX exe here and install it following the wizard. The installation is really simple (just follow the wizard), but if you need to, you can check out the official instructions.
Also refer to this link for full instructions to install the additional packages that may be needed by nbconvert.

ModuleNotFoundError: No module named 'azure.cognitiveservices.vision.customvision'

I am trying to use the microsoft azure custom vision service on a mac from Jupyter in VS Code
I have Python 3.8.3 installed.
I have done pip install azure.cognitiveservices.vision.customvision and confirmed it is there using pip show.
When I execute the command
from azure.cognitiveservices.vision.customvision.prediction import CustomVisionPredictionClient
I get the error:
ModuleNotFoundError: No module named 'azure.cognitiveservices.vision.customvision'
I have tried adding the location where the package is installed to $PATH but that does not fix the problem.
Any thoughts gratefully received! thx
It is recommended that you always create and activate a python virtual environment to work with Jupyter notebooks, like an Anaconda environment, or any other environment in which you've installed the Jupyter package.
To select an environment, use the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P). Once the appropriate environment is activated, you can create and open a Jupyter Notebook and connect to a remote Jupyter server for running code cells. Check Working with Jupyter Notebooks in Visual Studio Code for more info.
This is true for application development in Python in general as well.
A virtual environment is a folder within a project that isolates a copy of a specific Python interpreter. Once you activate that environment (which Visual Studio Code does automatically), running pip install installs a library into that environment only.
When you then run your Python code, it runs in the environment's exact context with specific versions of every library. You can create a requirements.txt file for the libraries you need, then use pip install -r requirements.txt.
Here is a snippet from a sample requirements.txt file:
azure-mgmt-core==1.2.0
azure-mgmt-network==16.0.0
azure-mgmt-resource==10.2.0
If you don't use a virtual environment, then Python runs in its global environment that is shared by any number of projects.
Refer to the Azure SDK for Python Developer docs for more information on configuring your local Python dev environment for Azure.
Whenever U get: ModuleNotFoundError, the simple solution is to install the module using
pip install (module name)
For example, in your case try to run the following line:
!pip install azure
The ! is to run a command in a notebook.

How can I add shared library in anaconda?

When I use python command, I can import library (boost.python) from code if .so files are stored in the same folder as .py script. How I can do this with anaconda and Jupyter Notebook?
Anaconda has a shell interface called “Anaconda Prompt”
inside the prompt, just use the following command:
conda install <yourPackageName>
and it will be available for your jupyter notebook
https://francescolelli.info/python/install-anaconda-and-import-libraries-into-the-ide/

Pandas and Jupyter not found after upgrading to Catalina

I just updated my macOS to Catalina and I can't run python or open a jupyter notebook from terminal anymore. As an example, I get error message "ImportError: No module named pandas" when running my python code, and I get
zsh: command not found: jupyter
when running
jupyter notebook
This issue has brought me to anaconda (I would love someone to explain me why. Does python need anaconda to be ran?). I have tried several suggestions from https://github.com/ContinuumIO/anaconda-issues/issues/10998, e.g. I have tried copying folder "anaconda3" from "Relocated items" folder to "Users//", then
export PATH=''/Users/<username>/anaconda3/bin:$PATH"
but I get either
dquote>
or
zsh: /Users//Applications/anaconda3/bin/conda: bad interpreter: /anaconda3/bin/python: no such file or directory
I then tried to reinstall Anaconda using the graphic installer (from https://www.anaconda.com/distribution/#macos) following advice from someone from the anaconda team (https://www.anaconda.com/how-to-restore-anaconda-after-macos-catalina-update/) (I changed installation location to a folder I created in /Users//) but I still get the same error messages when running python3 or jupyter notebook.
How can successfully run python and jupyter notebook with macOS Catalina?
After installed macOS Catalina, we can switch the terminal from bash to zsh. There are many advantages from using zsh instead of bash, but One of the issues with zsh is some of the frameworks (jupyter notebook,conda) are not supported directly. Once I typed jupyter notebook in terminal to run it. It displayed “zsh: no such file or directory”.
The solver is simple but very difficult to find online.
If jupyter was already installed before the update and stopped working after zsh, you should be able to fix it by:
1.open zshrc in terminal by typing: open .zshrc or $open .zschrc
2. add the following line at the end of the file:
source ~/.bash_profile
It will ask zsh to use all the information from bash like the path of jupyter.
Hope it can help you out!
I'm answering to my own question in case it can help others ;)
I found my answer here: https://medium.com/#singhaniatanay18/mac-os-catalina-update-zsh-instead-of-bash-d688f68f70b8
(see comments as well)
Mac OS BigSur:
Uninstall Anaconda:rm -f Anaconda-Navigator.app
re-install pip3 install jupyterlab
I just updated to Catalina, two days before Big Sur release.. oh well.
Catalina came with changes to security and bash, that will remain for future releases. So Catalina moves your anaconda3 folder to /Users/Shared/Previously Relocated Items/Security/anaconda3 I tried to move it back to home directory, but that didn't work. So I deleted it, and reinstalled Anaconda using the command line installer Not the GUI installer, and it worked for me. You can follow instructions here and use /Users/me/anaconda3 folder as recommended here.
Here are the commands that worked for me,
shasum -a 256 /Users/username/anaconda3 . Although not sure it did anything
bash ~/Downloads/Anaconda3-2020.02-MacOSX-x86_64.sh or whatever the name of the command line installer from Conda in your Download folder, or wherever else you downloaded it.
Use sudo in front of the command if permission was denied, then enter your log in password for your Mac
source /Users/username/anaconda3/bin/activate conda init zsh
sudo conda init zsh then enter your Mac's password.
You should be all set now, and all commands like ipython, conda info, jupyter notebook, pyspark will all work.
The last command will make step3 command persist i.e. initialize conda base environment, such that you can run conda, ipython, jupyter notebook the next time you use terminal.
Install the Jupyter using Homebrew in zsh shell
If you don't Python install 3.3or higher.
Open terminal
Using Homewbrew install jupyter
brew install jupyter
Now, you start a notebook
jupyter notebook

How to import pyodbc into Azure Data Studio for use in notebook?

I have installed the latest version of Azure Data Studio (1.6.0)
I don't have access to a SQLServer 2017/2019, only 2016, but would like to run some Python against it anyways from the notebooks now available in Azure Data Studio.
I would use pyodbc or pymsssql modules to do this.
but how do i add these modules to the environment?
I have downloaded the module, but when trying to add like this
pip install pyodbc-4.0.26-cp36-cp36m-win_amd64.whl
i get this error
Fatal error in launcher: Unable to create process using '"d:\0.0.1\python.exe" "c:\Users\bi_pt\azuredatastudio-python\0.0.1\Scripts\pip.exe" '
There is no path 'd:\0.0.1\' in my environment
and the python.exe is located here 'c:\Users\bi_pt\azuredatastudio-python\0.0.1\'
any ideas ?
regards
Peter
I know i shouldn't answer my own questions but i got these instructions from #MGoCode on Twitter:
"In the notebook choose any kernel other than SQL and click the Install Packages button on the toolbar.
That opens a terminal window in ADS where we change to the correct directory and give instructions on how to pip install"
and it works :-)
You also could go to the folder direction where is the Python version that Azure Data Studio is using and set there a txt with the names of the modules you need.
For example:
matplotlib
nltk
numpy
pandas
plotly
Put this txt in the same folder, where your python is installed. You could check your Python Path in Azure Data Studio in File / Preferences / Settings / Notebook configuration. Once you have placed your txt.
Place in cmd in this path and use pip install -r file.txt or pip install --no-cache-dir -r file.txt
and it works, at least to me! And I could have installed all the several modules I needed!

Categories

Resources