I have written a very long IPython notebook and need to convert it to PDF for distribution. I've read this thread but the solution didn't work for me.
I've tried the following:
If I use the Print button in my browser, I have all the IPython menu
etc. showing, which I can't accept.
If I use Print Preview from the IPython menu, none of the LaTeX equations render. They are all still just LaTeX code.
If I use ipython nbconvert --to latex --post pdf myfile.ipynb I get a FileNotFoundError. Traceback follows:
[NbConvertApp] Using existing profile dir: 'C:\\Users\\blokeley\\.ipython\\profile_default'
[NbConvertApp] Converting notebook myfile.ipynb to latex
[NbConvertApp] Support files will be in myfile_files\
[NbConvertApp] Loaded template article.tplx
[NbConvertApp] Writing 72246 bytes to myfile.tex
[NbConvertApp] Building PDF
[NbConvertApp] Running pdflatex 3 times: ['pdflatex', 'myfile.tex']
Traceback (most recent call last):
File "C:\Anaconda3\Scripts\ipython-script.py", line 5, in <module>
sys.exit(start_ipython())
File "C:\Anaconda3\lib\site-packages\IPython\__init__.py", line 120, in start_ipython
return launch_new_instance(argv=argv, **kwargs)
File "C:\Anaconda3\lib\site-packages\IPython\config\application.py", line 564,
launch_instance
app.start()
File "C:\Anaconda3\lib\site-packages\IPython\terminal\ipapp.py", line 367, in start
return self.subapp.start()
File "C:\Anaconda3\lib\site-packages\IPython\nbconvert\nbconvertapp.py",
line 268, in start
self.convert_notebooks()
File "C:\Anaconda3\lib\site-packages\IPython\nbconvert\nbconvertapp.py",
line 311, in convert_notebooks
self.postprocessor(write_resultes)
File "C:\Anaconda3\lib\site-packages\IPython\nbconvert\postprocessors\base.py",
line 28, in __call__
self.postprocess(input)
File "C:\Anaconda3\lib\site-packages\IPython\nbconvert\postprocessors\pdf.py",
line 140, in postprocess
cont = self.run_latex(filename)
File "C:\Anaconda3\lib\site-packages\IPython\nbconvert\postprocessors\pdf.py",
line 104, in run_latex
self.latex_count, log_error)
File "C:\Anaconda3\lib\site-packages\IPython\nbconvert\postprocessors\pdf.py",
line 84, in run_command
p = subprocess.Popen(command, stdout=stdout, stdin=null)
File "C:\Anaconda3\lib\subprocess.py", line 858, in __init__
restore_signals, start_new_session)
File "C:\Anaconda3\lib\subprocess.py", line 1111, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
If you suspect this is an IPython bug, please report it at:
https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev#scipy.org
You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.
Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
c.Application.verbose_crash=True
I'm using the latest updates from Anaconda in Python 3.4 64-bit on Windows 7 Professional.
Your issue is that you do not have LaTeX installed on your computer. When subprocess tries to call pdflatex myfile.tex it therefore fails as it cannot find pdflatex.
Whilst it's true that you can create .tex files from IPython notebooks without needing LaTeX, these are just files that contain the LaTeX code. To compile them to create PDFs you need a version of LaTeX.
Installing LaTeX on Windows is not difficult, MiKTeX is one possible installation.
Related
Dear Stackoverflow community,
I am using Selenium and Python to automate a task. When my program runs as myscript.py, it works seamlessly. I am converting myscript.py to myscript.exe using:
PyInstaller --onefile --windowed --icon="icon.ico" --add-data "icon.ico;." myscript.py
The resulting myscript.exe file does not work, giving the following error:
Traceback (most recent call last):
File "myscript.py", line 155, in <module>
File "myscipt.py", line 32, in main
File "webdriver_manager\chrome.py", line 39, in install
File "webdriver_manager\core\manager.py", line 30, in _get_driver_path
File "webdriver_manager\core\download_manager.py", line 28, in download_file
File "webdriver_manager\core\http.py", line 35, in get
File "webdriver_manager\core\utils.py", line 289, in show_download_progress
File "tqdm\std.py", line 1109, in __init__
File "tqdm\std.py", line 1361, in refresh
File "tqdm\std.py", line 1509, in display
File "tqdm\std.py", line 350, in print_status
File "tqdm\std.py", line 343, in fp_write
File "tqdm\utils.py", line 89, in __getattr__
AttributeError: 'NoneType' object has no attribute 'write'
Line 32 in main is:
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=options)
I am probably missing something fundamental. Any help from the community is greatly appreciated.
The issue is that webdriver_manager uses tqdm to show a progress bar in the terminal during the show_download_progress function, however since you are using the --windowed option with pyinstaller your program isn't run with a terminal. So when tqdm tries to show the progress bar there is nothing to write to, which is why it says NoneType object has no attribute 'write'.
This can be typically be solved by explicitly setting stdout and stderr to an object with a write method near the entrypoint to your application so they are set before any other code attempts to write to them.
For example:
import io
import sys
buffer = io.StringIO()
sys.stdout = buffer
sys.stderr = buffer
I am using Windows-10, Python 3.7, Pillow version 6.0.0, tkinter.
I developed a GUI tool which saves tkinter canvas as a PostScript using tkitner library, then converts it to PNG file using PIL (Pillow) library. On my Computer, I already have Ghostscript installed and my tool works just fine.
After distributing my tool with my collages, they can save the canvas as PostScript fine, but the tool then can't convert to PNG file and a anError arise regarding Ghostscript.
OSError: Unable to locate Ghostscript on paths
I would like to enable my Colleges of running the tool without the need of downloading Ghostscript on there machines.
I though then of including (bundling) the Ghostscript when creating py_app.exe using Pyinstaller.
Does anyone know how to do this, or have any other suggestions.
Below is the error message:
Exception in Tkinter callback
Traceback (most recent call last):
File "tkinter\__init__.py", line 1705, in __call__
File "user_input.py", line 49, in save_as
File "drawing_func.py", line 1232, in save_as_png
File "site-packages\PIL\Image.py", line 1973, in save
File "site-packages\PIL\Image.py", line 628, in _ensure_mutable
File "site-packages\PIL\Image.py", line 621, in _copy
File "site-packages\PIL\EpsImagePlugin.py", line 333, in load
File "site-packages\PIL\EpsImagePlugin.py", line 139, in Ghostscript
OSError: Unable to locate Ghostscript on paths
Note: This was flagged as a potential duplicate of this, but the point of my question is that using textract doesn't work. I am looking either for (a) a way to get textract to work on windows 10 or (b) an alternate solution.
I am building a system that needs to read various types of files. I have set up pdfminer to read the .pdfs, and based on the process outlined here I installed textract, and I can now also read .docx files. However textract relies on antiword for reading .doc files and I cannot get this to work, even after following the directions here I could not find and install a working version of antiword. I do not have microsoft word installed on my machine, and I am running windows 10 with python 3.6.5. Is there any other way to read .doc files?
Here is the bug when running textract.process('d.doc') (ignore the first error, the file is definitely there):
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\textract\parsers\utils.py", line 84, in run
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\ProgramData\Anaconda3\lib\site-packages\textract\parsers\__init__.py", line 77, in process
return parser.process(filename, encoding, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\textract\parsers\utils.py", line 46, in process
byte_string = self.extract(filename, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\textract\parsers\doc_parser.py", line 9, in extract
stdout, stderr = self.run(['antiword', filename])
File "C:\ProgramData\Anaconda3\lib\site-packages\textract\parsers\utils.py", line 91, in run
' '.join(args), 127, '', '',
textract.exceptions.ShellError: The command antiword d.doc failed with exit code 127
From the 'Windows installation problem' series: https://github.com/deanmalmgren/textract/issues/194#issuecomment-507243521
After following the steps to 'install' antiword, I was facing the same problem as yours.
Restarting windows after setting up the environment path variable entirely solved this exact error message for me. (This was the last error I was facing for handling .doc files with textract)
Installation instructions extracted from https://github.com/deanmalmgren/textract/issues/194#issuecomment-506065817
"Install Antiword
(I followed Reading .doc file in Python using antiword in Windows (also .docx))
Go to https://www.softpedia.com/get/Office-tools/Other-Office-Tools/Antiword.shtml
Extract to c:\antiword (yes it's required to be in the root directory)
Add location to path like we did tesseract-ocr [basically add c:\antiword to the system path (environment variable)]"
I was able to get part of the text using olefile, but olefile ultimately only handles bytes and does not handle the encoding of Word .doc files. The solution is to use LibreOffice, see my other question here
Regular PyCharm, Anaconda and Jupyter user, but for the first time I'm starting a project that would benefit with having them all play together:
I have a correctly configured Anaconda environment running within PyCharm, however when I try to launch ipynb notebooks (that work perfectly well in jupyter notebook from within PyCharm, I get...
/home/bolster/anaconda3/bin/python3.5 /home/bolster/anaconda3/bin/jupyter-notebook --no-browser --ip 127.0.0.1 --port 8888
[W 12:33:12.515 NotebookApp] Unrecognized JSON config file version, assuming version 1
[W 12:33:12.519 NotebookApp] Config option `matplotlib` not recognized by `NotebookApp`.
[W 12:33:12.521 NotebookApp] Config option `matplotlib` not recognized by `NotebookApp`.
Traceback (most recent call last):
File "/home/bolster/anaconda3/bin/jupyter-notebook", line 6, in <module>
sys.exit(notebook.notebookapp.main())
File "/home/bolster/anaconda3/lib/python3.5/site-packages/jupyter_core/application.py", line 267, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "/home/bolster/anaconda3/lib/python3.5/site-packages/traitlets/config/application.py", line 595, in launch_instance
app.initialize(argv)
File "<decorator-gen-7>", line 2, in initialize
File "/home/bolster/anaconda3/lib/python3.5/site-packages/traitlets/config/application.py", line 74, in catch_config_error
return method(app, *args, **kwargs)
File "/home/bolster/anaconda3/lib/python3.5/site-packages/notebook/notebookapp.py", line 1069, in initialize
self.init_configurables()
File "/home/bolster/anaconda3/lib/python3.5/site-packages/notebook/notebookapp.py", line 837, in init_configurables
parent=self,
File "/home/bolster/anaconda3/lib/python3.5/site-packages/nb_conda_kernels/manager.py", line 19, in __init__
specs = self.find_kernel_specs() or {}
File "/home/bolster/anaconda3/lib/python3.5/site-packages/nb_conda_kernels/manager.py", line 129, in find_kernel_specs
self.conda_info = self._conda_info()
File "/home/bolster/anaconda3/lib/python3.5/site-packages/nb_conda_kernels/manager.py", line 29, in _conda_info
p = subprocess.check_output(["conda", "info", "--json"]
File "/home/bolster/anaconda3/lib/python3.5/subprocess.py", line 629, in check_output
**kwargs).stdout
File "/home/bolster/anaconda3/lib/python3.5/subprocess.py", line 696, in run
with Popen(*popenargs, **kwargs) as process:
File "/home/bolster/anaconda3/lib/python3.5/subprocess.py", line 950, in __init__
restore_signals, start_new_session)
File "/home/bolster/anaconda3/lib/python3.5/subprocess.py", line 1544, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'conda'
I have a hunch that this is because PyCharm isn't attempting to launch the notebook in a "real" user environment and as such isn't getting my $PATH imports (in .profile), however as this isn't a "Run Configuration" I can't see any way to "point" the IDE to look in the right path for the conda executable.
However if I add a link to the conda executable to /usr/bin/, it works, but this is an order of hackery on a collaborative project that I'm not exactly happy with.
Is there a way to force PyCharm to look in the right place or at least update the internal-global environment variables to avoid seriously telling collaborators they need to link from their userland environment to the root bins?
Any application started from the terminal will inherit all the properties from the terminal. If you start the PyCharm the non-terminal way then the $PATH defined in the .profile won't be inherited and so the default $PATH.
Started the PyCharm from the shell and then $PATH from the .profile was inherited. Now, PyCharm is able to found conda in the path.
Another way is to create a .sh file in the /etc/profile.d folder with the PATH variable. These variables are system wide. So, there is no need to start PyCharm from the terminal now.
The reason for such a behavior and alternate solutions are specified in this StackOverflow post.
Hope this helps!
I am really new to the use of Python and the associated packages that can be installed.
As a biologist I am looking for a lot of new packages that would help me model species systems, ecological change etc.. and after a lot of "Google-ing" I came across scikit-learn.
However, I am having trouble installing it. And I will take this moment now to apologise for the length of this post.
I am using 64bit Python 3.3 and have the associated NumPy (MKL 1.7.0) and SciPy. I installed distribute which worked fine and allows me to use easy_install.
So to install scikit-learn, I tried using the cmd prompt (Windows) run in administrator mode, and then also through Python command line.
I placed the downloaded and extracted tar.gz file in the Lib\site-packages folder.
When I run the command
easy_install scikit-learn
in cmd prompt.
Then this is the following output:
C:\Python33\Lib\site-packages>easy_install -U scikit-learn
Searching for scikit-learn
Reading http://pypi.python.org/simple/scikit-learn/
Reading http://scikit-learn.org
Reading http://sourceforge.net/projects/scikit-learn/files/
Reading http://scikit-learn.sourceforge.net
Best match: scikit-learn 0.12.1
Downloading http://pypi.python.org/packages/source/s/scikit-learn/scikit-learn-0
.12.1.tar.gz#md5=7e8b3434f9e8198b82dc3774f8bc9394
Processing scikit-learn-0.12.1.tar.gz
Writing c:\users\nuvraj~1\appdata\local\temp\easy_install-kvr2q0\scikit-learn-0.
12.1\setup.cfg
Running scikit-learn-0.12.1\setup.py -q bdist_egg --dist-dir c:\users\nuvraj~1\a
ppdata\local\temp\easy_install-kvr2q0\scikit-learn-0.12.1\egg-dist-tmp-l618ie
Traceback (most recent call last):
File "C:\Python33\Scripts\easy_install-script.py", line 9, in <module>
load_entry_point('distribute==0.6.33', 'console_scripts', 'easy_install')()
File "C:\Python33\lib\site-packages\setuptools\command\easy_install.py", line
1937, in main
with_ei_usage(lambda:
File "C:\Python33\lib\site-packages\setuptools\command\easy_install.py", line
1918, in with_ei_usage
return f()
File "C:\Python33\lib\site-packages\setuptools\command\easy_install.py", line
1941, in <lambda>
distclass=DistributionWithoutHelpCommands, **kw
File "C:\Python33\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Python33\lib\distutils\dist.py", line 917, in run_commands
self.run_command(cmd)
File "C:\Python33\lib\distutils\dist.py", line 936, in run_command
cmd_obj.run()
File "C:\Python33\lib\site-packages\setuptools\command\easy_install.py", line
358, in run
self.easy_install(spec, not self.no_deps)
File "C:\Python33\lib\site-packages\setuptools\command\easy_install.py", line
598, in easy_install
return self.install_item(spec, dist.location, tmpdir, deps)
File "C:\Python33\lib\site-packages\setuptools\command\easy_install.py", line
628, in install_item
dists = self.install_eggs(spec, download, tmpdir)
File "C:\Python33\lib\site-packages\setuptools\command\easy_install.py", line
823, in install_eggs
return self.build_and_install(setup_script, setup_base)
File "C:\Python33\lib\site-packages\setuptools\command\easy_install.py", line
1103, in build_and_install
self.run_setup(setup_script, setup_base, args)
File "C:\Python33\lib\site-packages\setuptools\command\easy_install.py", line
1089, in run_setup
run_setup(setup_script, args)
File "C:\Python33\lib\site-packages\setuptools\sandbox.py", line 34, in run_se
tup
lambda: exec(compile(open(
File "C:\Python33\lib\site-packages\setuptools\sandbox.py", line 82, in run
return func()
File "C:\Python33\lib\site-packages\setuptools\sandbox.py", line 37, in <lambd
a>
{'__file__':setup_script, '__name__':'__main__'})
File "setup.py", line 33, in <module>
File "c:\users\nuvraj~1\appdata\local\temp\easy_install-kvr2q0\scikit-learn-0.
12.1\sklearn\__init__.py", line 86
print "I: Seeding RNGs with %r" % _random_seed
^
SyntaxError: invalid syntax
C:\Python33\Lib\site-packages>
So the little ^ seems to be pointing at the " after RNGS with %r. Which from what I can tell is in the 'init' file from the sklearn folder found in the .tar.gz file.
I also get the same result when running it in the Python GUI and command line.
How can I install scikit-learn with Python 3.3? Is there some way of building it or editing the file to get past this invalid syntax error?
Any help would be greatly appreciated. And I am very sorry for it being such a long post. I was just trying to get all the details in there.
Thanks
Simon
scikit-learn does not support Python 3 yet. For now you need Python 2.7.
Proper support for Python 3 is expected for the 0.14 release scheduled for Q2-2013.
I am no expert, but in my understanding the print statement in Python 3.* is now a function, called like: print(). So, a quick solution in this case is to change
print "I: Seeding RNGs with %r" % _random_seed
to
print("I: Seeding RNGs with %r" % _random_seed)