iPython nbconvert not working with headings - windows

Question:
How can I convert ipynb files to PDF if they have headings? I can't make it with the normal command.
Why I ask so:
I've been searching info for many days to get over this problem but I resign and ask it in here. I'm running iPython notebook (with python 3.4) on Windows 8.1 and when I use the command:
ipython nbconvert my file.ipynb --to latex --post PDF
to convert my notebooks to pdf it only works when my file has no headings. If I have the same file and I don't write any heading it works smoothly but the problem comes when I have to put one. It can't even convert the notebook to anything (not HTML, not just LaTeX format...).
My LaTeX distribution is working fine, I can make .tex documents with headings and so on... but the trouble is when I use the nbconvert to make PDF files with headings.
The error it throws is so long so here I paste the first section of it:
[NbConvertApp] Using existing profile dir: 'C:\\Users\\Me\\.ipython\\profile_default'
[NbConvertApp] Converting notebook headers.ipynb to latex
[NbConvertApp] Support files will be in headers_files\
[NbConvertApp] Loaded template article.tplx
Traceback (most recent call last):
File "C:\Program Files (x86)\Anaconda 3\lib\site-packages\IPython\utils\_process_win32.py", line 76, in _find_cmd
from win32api import SearchPath
ImportError: No module named 'win32api'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files (x86)\Anaconda 3\Scripts\ipython-script.py", line 5, in <module> sys.exit(start_ipython())
File "C:\Program Files (x86)\Anaconda 3\lib\site-packages\IPython\__init__.py", line 120, in start_ipython
return launch_new_instance(argv=argv, **kwargs)
...

FINALLY I got it!
First of all, when analysing the Error Code, we can see that the program asks us for the 'win32api'. To solve this problem, one must open the Anaconda Command Prompt as administrator and write:
conda install pywin32
With this, we will fix the missing package. But it doesn't end here, because if we try it again, a longer error will pop up so we also need to install the pandoc pack. In order to do this, we must close the command prompt and download it from here and run it with everything else closed.
Then, one can run smoothly the nbconvert command for everything, yay! :D
So remember, before using nbconvert, be sure that you have:
pywin32
pandoc

Related

How to set up gitpython on in Visual Studio Code so it is setup once

I am developing on OS/X using Visual Studio Code (1.30.1). My script works but each time I close and re-open Visual Studi Code, I have to setup GitPython again. I want to set it up once and have it work.
I am developing with GitPython which I set up as follows via the VS Code Terminal window:
python3 -m venv gitpy
source gitpy/bin/activate
pip install gitpython==2.1.11
The python file, anyfile.py, is simple (the only line that matters is as follows):
from urllib.parse import quote
If I close and re-open the code, I cannot run the script:
python anyfile.py
The error is as follows:
Traceback (most recent call last):
File "anyfile.py", line 1, in
from urllib.parse import quote
ImportError: No module named parse
I can fix the issue by running the following from the Visual Studio Code Terminal window:
source gitpy/bin/activate
pip install gitpython==2.1.11
What am I doing wrong? Thanks in advance.

cannot run scons - unable to find files

So I've installed scons via Anaconda's conda install scons under Windows 10 (Python 3.6) and could not execute it via the command line so I've added C:\Users\D\Anaconda3\envs\py36\Scripts\ to my Path (even tough C:\Users\Dominik\Anaconda3 was already in there).
Now I can execute it in the Powershell, but I get an error, because it is unable find engine files:
scons
SCons import failed. Unable to find engine files in:
C:\Users\D\Anaconda3\envs\py36\Scripts\..\engine
C:\Users\D\Anaconda3\envs\py36\Scripts\scons-local-3.0.1
C:\Users\D\Anaconda3\envs\py36\Scripts\scons-local
C:\Users\D\Anaconda3\scons-3.0.1
C:\Users\D\Anaconda3\Lib\site-packages\scons-3.0.1
C:\Users\D\Anaconda3\scons
C:\Users\D\Anaconda3\Lib\site-packages\scons
Traceback (most recent call last):
File "C:\Users\D\Anaconda3\envs\py36\Scripts\scons.py", line 192, in <module>
import SCons.Script
ImportError: No module named 'SCons'
Does someone know how to further investigate/fix this problem?
I found it thanks to nekomatic.
If you use the anaconda prompt (with the correct environment activated or in my case the correct shortcut leading to anaconda prompt in that environment), scons runs just fine.
See this link explaining how anaconda uses the path on windows and whats the advantage of using the anaconda prompt (mainly it dynamically manages PATH correctly for that session only with full knowledge of conda environments).

Problems finding modules after installing SimpleCV 1.3

I have recently installed SimpleCV on Windows 10 from the superpack. Everything went well during the installation, and I was able to successfully run the first example problem in "Practical Computer Vision with SimpleCV" (good book, btw) from within IDLE. Here's the code:
from SimpleCV import Camera, Display, Image
cam = Camera()
display = Display()
img = cam.getImage()
img.save(display)
Simple enough, and it worked fine. Where I ran into problems was when I tried to start up the SimpleCV console. First of all, no link was created on the Windows desktop, and there was nothing for SimpleCV on the Start menu. So, I tried the other methods listed in the book. First, from the console, I tried to run it as a Python module:
C:\User> python -m SimpleCV.init
And what I got back was:
ERROR:
Traceback (most recent call last):
File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "C:\Python27\lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Python27\lib\site-packages\SimpleCV\__init__.py", line 18 in <module>
from SimpleCV.Shell import *
File "C:\Python27\;ib\site-packages\SimpleCV\Shell\__init__.py", line 1, in <module>
from Shell import *
File "C:\Python27\lib\site-packages\SimpleCV\Shell\Shell.py", line 54, in <module>
raise(e)
ImportError: No module named IPython
Next, I tried the listed alternative: just starting python and importing and executing the Shell. Entering:
>>> from SimpleCV import Shell
resulted in the same error as above.
I also tried installing ipython by running pip. But, it looks like pip didn't get installed either.
So, what environmental variable did the installation program not set correctly? Just so you know, I posted this same question on the SimpleCV site, but have not received a response as of yet.
--- 23 Dec 2015
Chipping away at this. Read the banner on setuputils install. Ran Python27\Scripts\easy_install.exe. Can now call pip. However, entering this at the command line:
C:\Users> pip install ipython
gives this error:
C:\Python27\lib\site--packages\pip-7.1.2-py2.7.egg\pip\_vendor\requests\packages\urllib3\util\ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cuase certain SSL connections to fail. For more information, see...
So, I'm making progress. Any suggestions?
Have you tried to install ipython from source code?
$ tar -xzf ipython.tar.gz
$ cd ipython
$ python setup.py install
See https://ipython.org/ipython-doc/3/install/install.html
There are a lot of requirements more. I recommend the SimpleCV's github repository instructions https://github.com/sightmachine/SimpleCV#windows-8

cx_freeze builds Mac program that runs from command line but dies when clicked

I have a Python 2.7/PyQt4 program that I am attempting to freeze with cx_freeze. The program also uses requests, serial, xml.etree.ElementTree, and collections. Using the unmodified setup.py generated by cxfreeze-quickstart-2.7, I can successfully build as both a console program (python setup.py build) and an .app (python setup.py bdist_mac) in Yosemite using Python from macports. If I run the program directly either from the app bundle or the dist:
$ build/MacDISE-1.0.app/Contents/MacOS/macdise
$ dist/macdise
It runs exactly as expected. If I open from the command line:
$ open -a /Users/jeffemandel/macdise/build/MacDISE-1.0.app
I get the dreaded
LSOpenURLsWithRole() failed for the application /Users/jeffemandel/macdise/build/MacDISE-1.0.app with error -10810.
I worked through a number of potential issues raised by Dan McCombs (distutils.util.get_platform, sys.arg), but these don’t seem to be the problem. Through brute force trial and error, I found that if I put all of my code in a separate module, simply importing that module (without actually invoking it) causes the 10810 error, so I figured it was finding a library when run from the command line, but not from the app. I put the dist directory on a thumb drive and ran it on another Mac that doesn't have Python, Qt4, etc installed, and got this:
packages/cx_Freeze/initscripts/Console.py", line 27, in <module> File "macdise.py", line 4, in <module>
File "ExtensionLoader_PyQt4_QtGui.py", line 11, in <module>
ImportError: dlopen(/Volumes/NO NAME/dist/PyQt4.QtGui.so, 2): Library not loaded: /opt/local/Library/Frameworks/QtGui.framework/Versions/4/QtGui
Referenced from: /Volumes/NO NAME/dist/PyQt4.QtGui.so
Reason: image not found
When I look in dist, there is a file QtGui that is the same size as the one in /opt. So it seems the failure is dlopen(PyQt4.QtGui.so) returning a hard-coded path to the QtGui library. I'm guessing the solution is simple, but I haven't stumbled across it yet.
Update: I looked at the libraries in build/Contents/MacOS/PyQt4.*.so with otool, and these all have #executable_path (as opposed to hard-coded paths in dist). My stupid. So I repeated the process of moving the program, only using the MacOS folder rather than the dist folder, and executing macdise from the command line on my wife's MBP. The problem turned out to be in the way I was looking for the included_files. I changed this to:
if getattr(sys, 'frozen', False):
uiName = os.path.join(os.path.dirname(sys.executable), "tabDISE.ui" )
else:
uiName = "tabDISE.ui"
and it runs. What would have saved me a day would be a way to automagically dump the error message generated when executing from the command line to the console log. If someone knows how to do this, it would be a big help.

Virtualenv keeps loading global site packages on Windows

I've looked around on SO, and the answers I have found to my problem haven't allowed me to solve it yet.
I want to use isolated virtualenv environments, but for one reason or another, virtualenv keeps loading global site packages, when in django's shell...
I tried to clean up PATH variables, until only c:\Python26\Scripts and c:\Python26 remain. I then create my environment.
virtualenv --distribute --no-site-packages myproject
I then activate the virtualenv. PATH is now (irrelevant vars scrapped):
PATH=E:\Development\django_projects\myproject\Scripts;C:\Panda3D-1.7.0\python;C:\Panda3D-1.7.0\bin;c:\python26\Scripts;
PYTHONPATH=C:\Panda3D-1.7.0\
So far, so good. I launch python...
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named django
Let's just try a module I'm sure is in my c:\python site-packages directory.
>>> import BeautifulSoup
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named BeautifulSoup
Yay! No global site packages! On to the next one then. From the command prompt, I type:
django-admin.py
And it works! But wait... I haven't installed Django yet. How is this possible?
After this, it gets even weirder... I first add these to virtualenv's activate.bat script so that Django can find my settings.
set PYTHONPATH=E:\Development\django_projects\myproject\
set DJANGO_SETTINGS_MODULE=settings.development
Now I launch django-admin.py shell and
In [1]: import BeautifulSoup
In [2]: BeautifulSoup.__file__
Out[2]: 'C:\\Python26\\lib\\site-packages\\BeautifulSoup.pyc'
How is this even possible?
Flash of insight
While typing this, I suddenly get it. .py is a file extension coupled with my c:\python26\python.exe executable, instead of the virtualenv one!
python manage.py
Traceback (most recent call last):
File "manage.py", line 2, in <module>
from django.core.management import execute_manager
ImportError: No module named django.core.management
Heh. Anyone has any idea of how to couple the .py file extension to my virtualenv's python executable instead of the system defined python executable?
A little bit of extra .bat hackery can easily fix this. My standard additions to activate.bat are:
REM custom venv settings
set PYTHONPATH=%\VIRTUAL_ENV%;%\VIRTUAL_ENV%\conf;%\VIRTUAL_ENV%\apps
set DJANGO_SETTINGS_MODULE=settings
ftype Python.File=%VIRTUAL_ENV%\Scripts\python.exe %1 %*
and to deactivate.bat
REM restore ftype
ftype Python.File=C:\tools\Python27\python.exe %1 %*
You could make a .bat file and modify PATH and PYTHONPATH in there, and then run .py from that .bat file.
Something like this i think
set PATH=C:\Python26;
python myfile.py
Ofcourse, add anything else to your path that you want.
I had the same "Access denied" problems as Dan with m0nonoke's answer on my Windows 7 setup using cmd.exe.
But I found this work around using a replacement shell TCC/LE and a customised startup file...
Under working directory create subdirectory config. In this directory
create startup file for TCC/LE called tcstart.btm
#echo off
rem Override system python binding to handle virtualenvironments
set .py;.pyc=python.exe
Now create (copy) TCC/LE shortcut on desktop and rename it
appropriately. Open Properties for shortcut and add to Target
“C:\django\config\tcstart.btm”. You probably want to set Start in to
something useful, like C:\django
Solution found in this guide on installing Django and Windows.

Resources