Cytoscape gives extension error for GML files from Networkx - networkx

I cannot open any GML files with Cytoscape and I keep getting "wrong extension" errors whether I use ".gml" or no extension at all.
Cytoscape 3.8 using Java 11 on an Ubuntu machine. The files are written by the write_gml function of networkx.

You may be trying to import GML files as a session.
To import GML files you should do the following:
From the main menu select 'Import > Network from File...'
Select the GML format.
Select your file and click on 'Open'

Related

"Import "pyautogui" could not be resolved from source" while having pyautogui installed on VS Code

I'm having trouble right now with PyAutoGUI. I have installed it in:
C:\msys64\mingw64\lib\python3.9\site-packages
but VS Code doesn't seem to recognize it.
I get this message:
Import "pyautogui" could not be resolved from source
I've already tried reinstalling everything, set paths and verify installations.
Use Ctrl+Shift+P --> Python:Select Interpreter to select the correct interpreter.
If there are multiple python versions on your machine, you need to use the one that has the pyautogui package installed.
You can check the current interpreter path with the following code.
import sys
print(sys.executable)

VSCode: How to export a python file that was imported from a Jupyter Notebook back to Jupyter format?

Probably a silly question, but I couldn't find it. Visual Studio Code editor has a really nice way to work with Jupyter Notebooks. I can edit the cells directly in vscode and run them. Now it would be easy to work with version control.
But I couldn't find a way to convert it back to a Notebook! How do I generate a notebook back from the generated python file?
I understand that the notebook wouldn't have the output cells in it.
There is an option in the interactive Python window that has the notebook output:
This is really cool, now you can work in a Python file and have a really nice interface with your version configuration system (Git).
Yes, it was a silly question :-)
The Jupytext library supports the percent-based cell format used by VSCode-Python, as well as other text-based notebook interchange formats:
https://github.com/mwouts/jupytext
If you need more control over how conversion to ipynb is done (or you need to have cross-references) then you can give a try to Pandoctools. It can export VSCode *.py documents to any Pandoc output format or to Jupyter notebook.
For example you can create and register Jupyter kernel. For example is can be named "nn". That should be the same kernel that you selected in VSCode (there you select it by path but VSCode still uses installed kernels specs under the hood). Then add hat to the Python file, split document to cells, provide settings and set Markdown cells (commented metadata line would export to pdf instead of ipynb; I recommend to open ipynb in nteract native app):
"""
---
kernels-map:
py: nn
jupyter:
kernelspec:
display_name: nn
language: python
name: nn
pandoctools:
# out: "*.pdf"
out: "*.ipynb"
...
# Markdown section title 1
Some **static** Markdown text.
"""
# %% {echo=False}
import IPython.display as ds
import math
import sugartex as stex
# %% {markdown}
"""
# Markdown section title 2
The quick brown Fox jumps over the lazy dog.
"""
# %%
ds.Markdown(stex.pre(f'''
Some **dynamic** Markdown text with SugarTeX formula: ˎα^˱{math.pi:1.3f}˲ˎ.
It works because of the `Markdown` display option and `sugartex` Pandoc filter.
Acually `stex.pre` is redundant here but it is needed when the text is imported
or read from somewhere instead of being written in the same document.
'''))
Then convert the file via pandoctools: drag and drop file to pandoctools shortcut/executable or "open with" pandoctools executable.
Also see:
Two introduction articles are at the beginning of this README,
examples of input to output conversion that have cross-references!
how to use Pandoctools and it's CLI,
how to use Knitty that collects Jupyter outputs and change it's settings.
Use jupytext library:
Install:
pip install jupytext
Now open CMD or internal terminal to the folder with your .py file
Run this:
jupytext --set-formats py:percent,ipynb filename.ipynb

jupyter setup i18n on exiting notebook

I have been trying to translate jupyter notebook interface with my native language, using existing i18n implementation. I have already created translation files just like readme advised and now i want to add it to jupyter.
https://github.com/jupyter/notebook/tree/master/notebook/i18n
but i can't find /notebook/i18n/ folder on my computer ( Ubuntu 16.04 ).Do i have to install jupyter one more time or can i just add translate files to already existing jupyter installation on my machine and run it?
I just reinstalled jupyter and this time i18n folder is on its place in:
/usr/local/lib/python3.5/dist-packages/notebook/i18n/i18n
First, find lib_path by python:
import sys
from distutils.sysconfig import get_python_lib
print (get_python_lib())
And you will find it in
${lib_path}/notebook/i18n/

Convert ipynb to pdf in Jupyter

I am new to ipython notebook, and I would like to convert my ipynb to pdf. But I get the following error when I try to Download as PDF via LaTex.
nbconvert failed: pdflatex not found on PATH
There is no documentation anywhere how to add pdflatex to my PATH. I use windows. Thank you!
A simple and surprisingly good solution is to print the notebook to pdf through the browser with ctrl+p. Just make sure your plots and figures are not on interactive mode otherwise they will not be displayed (set them to %matplotlib inline).
Exporting jupyter notebooks through latex is quite troublesome and takes a lot of tinkering to get something remotely close to publish ready. When I absolutely need publication quality I do it on a latex editor, but this tutorial goes in great length about doing it on jupyter.
A few useful tips to get better results:
Higher resolution plots
Hide your code-cells from the pdf
Take a look at these extensions to improve your jupyter documents
For Mac OS X, the solution for me was to install MacTex first and then export the path to find it:
### TeX
export PATH="/Library/TeX/Distributions/.DefaultTeX/Contents/Programs/texbin:$PATH"
You can add this to your .bash_profile or similar config file to load it every time.
See more here https://github.com/jupyter/nbconvert/issues/406
As said by Thomas K in the comments, you need to have Latex installed, and after add the path to the directory containing pdflatex.exe file to the PATH variable of your system.
I have looked for a lightweight distribution and tried installing TeXworks, but I didn't find any pdflatex.exe file.
So I have tried TeX Live, which worked fine creating the pdflatex.exe file under the target installation directory. This path should be like C:\...\texlive\2016\bin\win32.
Finally, you should just add this path to the PATH environment variable of your system (you can use the link shared by Thomas K).
As said here, you need to quit jupyter notebook and open a new command prompt after making any path changes, in order for jupyter to find the newly added item to the PATH.
Then, in Jupyter, you can check your environment variables by running the following (refer to this link for details):
import os
os.environ['PATH'].split(';')
and check if it contains the path to pdflatex.exe file.
If you get some trouble when exporting your notebook to pdf due to missing files/packages (this happened to me), refer to this link to search and install them under TeX Live.
For Linux, the reported error is due to the lack of XeLatex, part of the texlive-xetex package.
Installation in ubuntu will be:
sudo apt install texlive-xetex
Instead of using nbconvert what you can do is :
Download your ipynb file as HTML from File option.
Right-click and select print or use Ctrl+P.
Save as PDF
Easy.
Here is the full solution that worked for me (for Mac).
brew cask install mactex
$ cd ~/
$ touch .bash_profile
This will open the bash profile on TextEditor
$ open -e .bash_profile
Paste the following to the top and save
export PATH="/Library/TeX/Distributions/.DefaultTeX/Contents/Programs/texbin:$PATH"
Close any notebook you have and reopen it
Here is the notebook explaining it step by step:
https://github.com/ybaktir/notes/blob/master/Convert%20Jupyter%20Notebook%20to%20Pdf.ipynb
I agree that latex installation (at least on windows) is painful and the result in my case was not a great looking document. The ctrl-p method alone doesn't work great if you're running in JupyterLab, but if you export the notebook to HTML, then print from the browser, choosing PDF, the result is quite good.
I know my solution is not at a level. But it works !!
in your browser of notebook tab, simply do "ctrl + p" to get download in pdf
First export the notebook file to HTML (available through File> Download as..).
If you are using JupyterLab, then this is available under File > Export Notebook As....
Use (any) free online converters to convert html file to a pdf file. (One such free online converter is sejda (https://www.sejda.com/html-to-pdf)
Note, there are many such converters are available online.

Importing arcpy module into anaconda's Spyder

I would like to use arcpy into Anaconda's Spyder. I have a full ArcGIS license, so this is not an issue. I am able to semi-import the module by way of copying the the arcpy folder out of C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy and into C:\Anaconda\Lib\site-packages, but the import is never completed because I get an error of "ImportError: No module named arcgisscripting". Is there any way for arcpy to work in Spyder?
This is what you need to do:
Open the Python window in ArcGIS, as described here
In there run these two commands:
import sys
sys.executable
Copy the output of the last command
Open Spyder and go to
Tools > Preferences > Python interpreter
Select the option
Use the following Python interpreter
and paste there the result of step 3.
Finally go to Consoles > Open an IPython console. This will open a new console that will be running the same Python version that comes with ArcGIS but inside Spyder. So you could run there whatever command you can run in ArcGIS Python Window.
Note: It is possible that this doesn't work if the Python that comes with ArcGIS doesn't have the ipykernel package.
To address this, browse to the python27\Lib\site-packages folder, mine was located under "C:\Python27\ArcGIS10.1\Lib\site-packages", and find the file Desktop10.1.pth.
On my system, the problem was resolved by simply copying the Desktop10.1.pth file into "C:\AppData\Local\Continuum\Anaconda\Lib\site-packages".
If you are running Anaconda 64 bit, you will get a different error when you try to import arcpy because ArcGIS runs 32 bit. Therefore, you have to make sure that you have the Anaconda 32 bit installed rather than 64 bit so things match up with ArcGIS. Once the file is copied and you have Anaconda 32 bit, import arcpy should work.
The only thing worked for me is: I just copied the arcpy folder from 'C:\Program Flies(x86)\ArcGIS\Desktop10.3' and pasted that into my '~Anaconda3\Lib\site-packages'. Now I can import arcpy into spyder of Anaconda3.