Now Google Colaboratory supports Python2 and Python3 kernels. Can I add a Go kernel so that I can use Go in Colab too?
I found a few examples here, but it only has JavaScript and R, not for Go language.
Use this notebook, which you can remember easily with the shortcut bit.ly/colabgo or colab.to/golang.
Previous methods depend on having 2 notebooks, one for installation, the other for running. Now both tasks must be done in the same notebook above.
The notebook specify gophernotes as the kernel. At first it cannot be found, so Colab will default to python3. Just run the first cell, which will install gophernotes for you.
When the first cell finish, reload the browswer (Ctrl+R or use MENU). Colab will now find gophernotes. It can now run golang in any cell, except the first (which is python..ish).
Here's the code of the first cell, for reference. You cannot use this in a new Python notebook, because there is no way to change kernel to gophernotes. You can only do that by text editor, or copying another notebook.
!apt install golang-go libzmq3-dev
%env GOPATH=/root/go
!go get -u github.com/gopherdata/gophernotes
!cp ~/go/bin/gophernotes /usr/bin/
!mkdir /usr/local/share/jupyter/kernels/gophernotes
!cp ~/go/src/github.com/gopherdata/gophernotes/kernel/* \
/usr/local/share/jupyter/kernels/gophernotes
Related
The wget command should work in Jupyter Notebook of VS Code as well since it worked in Google Colab.
You need to have wget installed in order to use it. Relying on external command might cause issues like one that you have encountered. If you want your code to be portable, then avoid relying on such command if possible.
Python standard library has function urllib.request.urlretrieve which will download file for you and is easy to use, consider following simple example
from urllib.request import urlretrieve
urlretrieve("https://www.example.com","example.html")
which does download Example Domain page and save it as example.html in current working directory
I try since multiple days to install solaris (https://github.com/CosmiQ/solaris) locally, on google colab or on renkulab (https://renkulab.io/). Up to now, without any luck. I tried on all platform different approaches:
Creating a conda environment (as recommended by the authors)
Directly through pip
And also cloning the repository and access the folders and functions directly
All of these approaches failed so far. Mostly there is a wheel building error for GDAL. Which i have installed first. I do not find any proper documentation or other failure descriptions which makes me question myself... Maybe here someone has experience with this library?
I highly appreciate every hint.
Thanks a lot
Colab Setup
I can get it set up in Colab with the following:
First Cell: Install Mamba/Conda
!pip install -q condacolab
import condacolab
condacolab.install()
This will trigger a runtime restart - it does this on purpose.
Second Cell: Install Solaris prerequisites
I'm assuming we want the GPU-enabled version. If not, there is another YAML in the solaris repository for a CPU-only environment.
!wget https://raw.githubusercontent.com/CosmiQ/solaris/main/environment-gpu.yml
!mamba env update -n base -f environment-gpu.yml
Manually restart the runtime after this completes!
Third Cell: Install Solaris
!pip install solaris
That should be it. Following these steps, I could import the module and use the entrypoints, e.g.,
Module import ✅
import solaris
Example entrypoint ✅
!make_masks -h
There were some future deprecation warnings from NumPy about some syntax in the TensorFlow code, but otherwise, seems functional. However, I don't personally use this tool, so I don't know if there is more to verify.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 10 months ago.
Improve this question
I decided recently that I want to start learning to code. I chose python as my first language because of it's versatility and Open Source connections. Now, of course to learn any programming language, first you have to be able to practice with it by writing code and running it.
I have Python beginner tutorials I am using but as soon as I got to the point where I wanted to run a simple Hello World message, I couldn't figure out how to get my document to actually RUN. I downloaded LiClipse with the hopes of using PyDev. I read that you can run a code directly from PyDev.
Wow, what a confusing mess! I downloaded the instant install version of LiClipse and I had to manually update the pip because it was out of date and that took an hour of research all on it's own to figure out how to do it.
Now that I have the interpreter set up correctly with the most recent pip...(I THINK), when I try to run any code I write, it doesn't let me. It wants me to save it first, which of course is quite logical. But when I try to save it, it says there is no folders to save to. How can there be no folders? I have been reading the install help, but it doesn't say anything about this issue. Or maybe it did explain how to fix this issue and I simply didn't understand all the jargon included in the configuration documentation. It kept instructing me to do technical things I couldn't understand.
Can anyone tell me what is going on? Shouldn't this all be ready to go when I used the "instant install" ?? I am just a beginner here, I don't know all this technical installation jargon. If anyone can help me get this setup, please let me know.
I really want to start learning. But I can't if I don't have the right tools.
Yeah, the technical jargon can be really confusing in the beginning. I've never heard of LiClipse but I can give you a few tips to get started:
Use a good IDE or Editor. For beginning VsCode with the Python PlugIn is quite good. You can also use PyCharm (the free version is enough) but that IDE is quite confusing.
Get comfortable with the commandline. On Windows you can invoke Python by running py on Linux with python3. You open the commandline on Windows by opening the startmenu, entering cmd and hitting enter.
You will have to make sure Python is in your "PATH" enviroment variable. That is a variable telling the Operating System where to find your programms. It should have asked you whether you want to add Python to your PATH during the install.
You run your python programm by saving it as a .py file and running py <filename.py> or python3 <filename.py> on Windows or linux respectively. You have to be in the directory where you saved your file of course.
I hope I could help you. Please mark this answer as accepted if it did answer your question or helped you with your issue.
I want to start by saying I'm mainly experienced in C & C++, not Python, but with programming in general many of the concepts carry over. I also don't have enough rep to comment, or I'd ask for some clarification on how familiar you are with the commandline.
I'm going to assume you're on Windows since you didn't mention the platform.
I wrote this like a tutorial, because I found those to be very helpful when I first started programming.
I can't recommend this enough, start off by using the commandline!
I think you complicated things more by searching for a text editor that can also run code. In order to get something like that working for your setup you need to know what's happening behind-the-scenes first.
Once you have a grasp of how to write & execute Python code, then you can move on to an IDE or advanced text editor like Visual Studio Code or LiClipse with confidence.
R+Click on the Start Menu, then click on Windows PowerShell to open a terminal.
Take a moment to note the filepath shown before the blinking cursor.
This is known as the Working Directory, which works similar to how the file explorer only allows you to "view" one directory at any given time; You can open multiple explorer windows side-by-side, but you can't view multiple directories at the same time in a single window.
You can run commands by typing them and pressing Enter.
You can also use the Tab key to autocomplete things like directory/file names, commands, etc. after typing a few characters.
Now let's create a workspace directory for your first project.
This can be anywhere that you choose, but for the sake of simplicity I'll be using my User directory which is usually where PowerShell will start by default.
To create a new directory named _workspace, use the mkdir (Make Directory) command like so:
mkdir _workspace
Now let's change our working directory to _workspace by using the cd (Change Directory) command like so:
cd _workspace
This directory is empty, but if you want to view the contents of a directory you can use the ls (List Directory) command:
ls
Since this is an empty directory, nothing will happen.
Next, we'll create a Python script file using the touch command, which creates empty files:
touch HelloWorld.py
Now that we have a script file, open HelloWorld.py in Notepad by running this command:
notepad HelloWorld.py
If you use a dark desktop theme, now is the time when your retinas may be seared out by the intensity of Notepad's white color scheme.
Now, let's add the code to print "Hello World!" in Python:
print("Hello World!")
Once you're done, you can save & close Notepad to save your retinas.
Now it's time to run the program! In the PowerShell window, enter this command:
py HelloWorld.py
which will show:
Hello World!
If you see an error saying this:
The term 'py' is not recognized as the name of a cmdlet, function, script file, or operable program.
You should re-install Python and make sure you check this box in the installer:
After re-installing Python and checking the Add to PATH box, close and reopen the PowerShell window, enter the cd _workspace command again, followed by py HelloWorld.py, which should be successful this time.
I hope I could be of some help, if so, I'd greatly appreciate marking this answer as accepted so I can write comments. Happy coding!
If you are using Linux following will work.
Install python3 first (Its better to stuck on python3 now. Once you get use-to then you can code in python2.7 also.)
Open a terminal, go the folder contains your code. If your source code is in hello.py then type python3 hello.py on terminal. It will execute and print the output on terminal.
The suggestions given by both #radj and #C. Dautermann are excellent.
Like others here, I will be assuming that you are on Windows.
Before jumping into LiClipse and PyDev, I highly recommend making sure that Python and packages (such as pip) are functioning on their own first. Command line is a great tool for this.
Windows Command Line can be accessed in a variety of ways, one of which is to go to your start menu and search "cmd." Command Prompt should return. In the command prompt, run the following:
python
This should return the version of Python installed on your machine if it is configured properly. For example, you may see the following:
Python 3.10.1 (...)[...] on win32
If this does not appear, I recommend uninstalling Python and reinstalling. In the installer, you will want to check the "Add Python ... to PATH" option. This will configure your environment variables on your machine. If you plan on running multiple versions of Python down the road, don't worry; you can use batch files to set the PATH variable to another version.
Once you have Python working, your command prompt will lead with the following:
>>>
Notice that there is no longer a file path followed by >>. This is because you are now in the Python interpreter. Congratulations!
To exit the Python interpreter, enter Ctrl+Z. It should appear as the following:
^Z
After we know Python works, we will check to see that pip works. Ensure you have pip installed by entering the following:
python -m pip --version
You should then be able to see the pip version. For example:
pip 22.0.3 from C:\...
If pip is not working, you can consult this documentation on pip to make sure pip gets installed properly.
Once pip is working, again, congratulations! You've gotten over some of the biggest hurdles. At this point, you can open up any text editor, type in:
print('Hello World!')
save the file with the extension .py, then run the script through command prompt. To run a script through the command line, you have to cd to the file location, then run the script with python, like so:
cd filepath
python filename.py
Where filepath is the path to the Python file and filename is the name of the file. For example:
cd C:\Users\name\Documents\PythonPractice
python helloworld.py
Usually, command line is all that is needed when starting out with Python outside of a text editor. Notepad comes standard on Windows computers, but there are plenty of other editors out there. Sublime text and Notepad++ are some of my favorites, personally.
Now, if you're able to run everything prior, the good news is that your Python and pip are both working, and you have everything you need to get started learning Python. If Python and/or pip are not functioning, there's thankfully a huge body of troubleshooting tips out there.
Unfortunately, from what I get of your initial post, you might be struggling with configuring LiClipse. I personally do not use LiClipse, nor do I use PyDev, so my help at this point may be limited. You may want to uninstall and reinstall after confirming your Python and pip work as a first step. After that, perhaps check that you are following the practices outlined in the LiClipse manual. Worst case scenario, you can try a different version of Python (I believe it has some Python3 incompatibilities), try running PyDev independent of LiClipse, or look at a different tool. If you believe the problem lies with file locations/existence, I would look at radj's post or play around in File Explorer to see what is going on for yourself.
Again, to get familiar with Python, you don't even need these extra tools. All you need is a text editor and the command line to get started.
Some other tools to help you get started:
PyPI
A venv virtual environment tutorial
PyDev
A comparison of LiClipse alternatives in case you continue to struggle
Hope this helps. Happy Coding!
Google Co-laboratory notebook doesn't have the "Download as" dropdown menu item in "File" menu like standalone Jupyter does. How to download the notebook as PDF?
You can also run the solution of mayurmadnani directly on Colab.
Therefore create a new Python workbook in Colab and connect it to a runtime.
Install the necessary packages into the virtual machine with:
!apt-get install texlive texlive-xetex texlive-latex-extra pandoc
!pip install pypandoc
Mount your google drive to get access to your ipynb files
from google.colab import drive
drive.mount('/content/drive')
I had to copy the files from the drive to the working directory,
because the drive is/was mounted as read only.
!cp drive/My Drive/Colab Notebooks/Untitled.ipynb ./
Then you can run the converter.
!jupyter nbconvert --to PDF "Untitled.ipynb"
Then you can download the file in the left side panel.
Use the built-in browser print. Then, save the result as a pdf.
#user10914779's answer worked for me. But if you are looking for a shorter and readable code then you can take a look at this Github repo: colab-pdf.
You can paste the following code in the last cell of your colab notebook and run it. It will generate a PDF file and save it to your drive.
!wget -nc https://raw.githubusercontent.com/brpy/colab-pdf/master/colab_pdf.py
from colab_pdf import colab_pdf
colab_pdf('name-of-the-notebook.ipynb')
You can provide the name of the notebook to colab_pdf('name-of-the-notebook.ipynb'). If you are not interested in the output that this codeblock produces then you can hide it using '%%capture'
%%capture
!wget -nc https://raw.githubusercontent.com/brpy/colab-pdf/master/colab_pdf.py
from colab_pdf import colab_pdf
Try any one:
You have an option File > Download .ipynb. Use below command to convert ipynb to pdf or any other format
jupyter nbconvert --to FORMAT notebook.ipynb
See usage guide: https://nbconvert.readthedocs.io/en/latest/usage.html
As mentoned by Bob, use print option to save as pdf. Here, you may lose text if it goes out of the page
Download .ipynb file
Download as html
Print PDF from browser
check here for video: https://youtu.be/n2Cd9NCZtZk
%cd go_to_your_path
#run these.
!sudo apt-get install texlive-xetex texlive-fonts-recommended texlive-generic-recommended
!jupyter nbconvert --to pdf fileName.ipynb
so to browser print option and select cancel option in that you will get save as pdf.
download the .ipynb file from colab from file->download .ipynb
Then upload it to your jupyter notebook and download it in pdf format as you used to in stand-alone jupyter.
Since .ipynb files take a few MBs of data at maximum.
If (You are using jupyter the easier way I found was to)
Download the file in latex.
Upload it to overleaf.
And then download it as a pdf
Else if ( You are using google collab)
Download as ipynb
Upload to jupyter and repeat the above steps.
You first download the related packages for it with the following code:
!sudo apt-get install texlive-xetex texlive-fonts-recommended texlive-plain-generic
Then run the code below to convert the corresponding named IPYNB file to convert to the same name PDF file.
!jupyter nbconvert --to pdf /content/Text_Summarization.ipynb
A Note:
If you have any blanks on the file name, you should add a backslash to the code just like below:
!jupyter nbconvert --to pdf /content/Text\ Preprocessing\ and\ BoW.ipynb
For macOS users, I found exporting to PDF with nbconvert following these steps worked well.
Run the below commands in your terminal. If using Anaconda, ensure to run them in the base environment.
pip install nbconvert[webpdf]
jupyter nbconvert --to webpdf --allow-chromium-download path/name_to_notebook_file.ipynb
PS: The --allow-chromium-download flag should be added once to install Chromium.
If you want to exclude code in the PDF export, run jupyter nbconvert --to webpdf --no-input path/name_to_notebook-file.ipynb
Ref: https://mljar.com/blog/jupyter-notebook-pdf/
For me the easiest way in collab:
***ctrl+P*** (Print) and there, instead of printing the page, just click Microsoft Print to PDF. You will have your notebook in PDF in your downloads.
If you are using colab -
go to file then click on print,
there will be a "destination" tab,
choose the "save as pdf" option over there
Matplotlib now requires python to be installed as a framework to use it in interactive mode (Working with Matplotlib on OSX), which I do as:
python -m venv my-virtualenv
source my-virtualenv/bin/activate
This works fine. For example, if I do:
my-virtualenv> pip3 install tensorflow
in this new environment it builds tensorflow fine and I can import it fine when I enter the python3 shell within my-virtualenv. However, when I create a symbolic link:
ln -s my-virtualenv/bin/python3 /usr/local/bin/python36x
and then enter the python36x shell tensorflow e.g. is not available. I've tried
python -m venv --copies my-virtualenv
as well to no avail. How can I create a functional symbolic link?
Python3's venv creates a link to the virtual environment's bin/python instead of copying the file like virtualenv. Python2's loader would follow links until the actual python executable was located, then use that directory to locate the libraries (../lib/). Python3's loader does not follow the links, but uses the directory of the python (link or not) to locate the libraries.
You can use an alias instead of a link:
alias python36e=my-virtualenv/bin/python3
It's not on the path but is directly accessible.
A better solution would be putting a wrapper script on your path.
# cat /usr/local/bin/python36x
myprog=my-virtualenv/bin/python3
exec "${myprog}" "$#"
HTH
OK, Pycharm actually has its own way of dealing with this: see how to set the interpreter to use across multiple platforms. Pycharm is very nice!