How to get Sphinx working in PyCharm with Python 3.5 - python-3.x

This is my first time using Sphinx in PyCharm 5.0 with Python 3.5.
When I run sphinx task in PyCharm I get the following error:
File "C:\Program Files (x86)\JetBrains\PyCharm 5.0\helpers\docutils\__init__.py", line 63, in <module>
class ApplicationError(StandardError): pass
NameError: name 'StandardError' is not defined
On this page I discovered that in Python 3.x StandardError is now replaced with Exception. However, when I try to edit the __init__.py file PyCharm prevents me from saving it.
I also noticed that __init__.py is based off of docutils version 0.8. This is not intuitive since I installed docutils version 0.12 in my virtualenv. Meaning that version 0.12 is being ignored.
Does anyone know how to fix this?

Update: PyCharm 5.0.2 fixes this, and Sphinx run configurations work under Python 3
Unfortunately the Python code shipped in PyCharm pre-5.0.2 helpers is not Python 3 compatible. The PyCharm issue tracker has a ticket. I once gave a crack at fixing all the small boo-boos, but then ran into some bigger ones.
So instead, just make a Run Configuration that calls:
Script (on Mac): /Users/paul/projects/jetbrains/env35/bin/sphinx-build
Script parameters: -b html -d _build/doctrees . _build/html
...and set the working directory to the place you want the _build directory.
Edit: Added a link for how to create and edit run/debug configurations in pycharm and a screenshot for windows. Script location is 'Scripts' as opposed to 'bin'.
Creating and Editing Run/Debug Configurations in PyCharm 5.0
PyCharm 5.0 Screenshot (on Windows)

Related

import win32api in python 3.7 resulting in dll import error

I am having the error while running jupyter notebook. Error replication:
python --version
Python 3.7.9
python
import win32api
The error was: ImportError: DLL load failed
After doing a some stackoverflow, I got to know that there are 2 dll files missing namely: pythoncom37.dll and pywintypes37.dll
I also got to know that I can run this post command: pywin32_postinstall.py in the Scripts folder. I ran this script. Restarted my pc. I manually download these two dll and copied it to my system32. After manually downloading, I started to have a different type of error: ImportError: DLL load failed: %1 is not a valid Win32 application
I used anaconda and ran my jupyter notebook which was my main aim but can you please make me aware as what is going wrong?
I've run into this recently, but with a different version of the DLLs. What solved it for me was using a different version of pywin32.
My solution (conda env, python 3.8.5):
pip install pywin32==300
or try 225, 227, 228. The latest pywin32 (301 as of this post) seems to be having dll search issues (I wouldn't be surprised if whatever version you were using is also having dll search issues). 301 was released after your issue started, but you may have a similar problem nonetheless.
There is currently an issue on pywin32 DLL loading failing: https://github.com/mhammond/pywin32/issues/1709
Factors involved (in my experience) include your PATH variable (if you're using conda). I haven't tested it myself, but I'd be curious to see if this issue occurs without conda. This issue stops happening for me if the first dlls found are those for 301. In my case, that means putting them in my C:\Windows\System32 folder (yeah I'm on Windows; joy).
So a possible solution #2 would be to run the pywin32 post install script which should be located under your venv/Scripts/pywin32_postinstall.py
To try that solution, open an ADMIN command prompt (very important that it's admin), navigate to your venv, and run:
ppython.exe Scripts\pywin32_postinstall.py --install
You shouldn't HAVE to do this, but if you just need a one-off solution and it works, great!
pip install --upgrade pywin32 ==225 worked for me. Tried version 300 and was unsuccessful.

Building NSIS from source on windows (VS2012)

I'm working on a pure x64 version of my software. Our installer for the x86 version is NSIS and my software is built using VS2012. I found online that in order to build x64 installers using NSIS you have to build NSIS (and all plugins/etc) from source. That is the end goal. However, right now I'm having issues just building x86 (before moving on to x64) using the instructions in the NSIS docs. https://nsis.sourceforge.io/Docs/AppendixG.html#build_windows
I'm trying to build NSIS v3.0.4 which uses SCons to build. I've installed scons using pip (SCons version 3.1.1).
However, when trying to build NSIS, I get the following (using python 3.8.0).
C:\Source\nsis\nsis-code-r7069-NSIS-tags-v304>scons ZLIB_W32=C:\Source\zlib-1.2.7 MSTOOLKIT=yes
scons: Reading SConscript files ...
TypeError: cannot use a string pattern on a bytes-like object:
File "C:\Source\nsis\nsis-code-r7069-NSIS-tags-v304\SConstruct", line 263:
for v in re.compile(r'^\\H\{[v]?(\S+)\}', re.M).finditer(File('#/Docs/src/history.but').get_contents()): # Try to parse the Halibut history file
the section of the SConstruct file is as follows (starting at line 260 so the for loop starts at 263):
if not defenv.has_key('VER_PACKED'):
import re
found = None
for v in re.compile(r'^\\H\{[v]?(\S+)\}', re.M).finditer(File('#/Docs/src/history.but').get_contents()): # Try to parse the Halibut history file
if v and not found:
v = v.group(1).split('.')
if len(v) >= 2:
mi = int(re.search(r'\d+', v[1]).group())
if mi < 1: mi = 1 # Make sure we can subtract 1 from the minor number so trunk stays below the next release
defenv['VER_PACKED'] = '0x%0.2i%0.3i%0.2i%0.1i' % (int(re.search(r'\d+', v[0]).group()), mi - 1, 66, 6)
if int(defenv['VER_PACKED'], 0) >= int('0x03000000', 0):
found = v
if not found:
defenv['VER_PACKED'] = '0x%0.2i%0.3i%0.2i%0.1i' % (3, 3, 42, 0) # Default to a version number we never used
print('WARNING: VER_PACKED not set, defaulting to %s!' % defenv['VER_PACKED'])
At this point, I'm not sure if there is a dependency I'm missing or if this is an issue with the build script and needs to be reported at the NSIS issue tracker. Ideas?
-UPDATE 1-
Based on suggestions from #Anders, first I tried to build the head of the repo (r7132 trunk) instead of v3.0.4 using Python3. This got me farther but still failed on what appears to be Python2 vs 3 syntax errors in mstoolkit.py (might be a symptom of another issue rather than the cause though). I didn't investigate this too much further yet.
So next, I went back to Python 2.7. This got me further but the mstoolkit.py appears to be dependent on VS2003 implementation. I duplicated the VCToolkitInstallDir environment variable on my machine using the contents of the VS110COMNTOOLS (C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools) but that fails also:
File "C:\Source\IQClient_Interim\Shared\third_party\nsis\nsis-code-r7132-NSIS-tags-v304\SCons\Tools\mstoolkit.py", line 87, in get_msvctoolkit_paths
raise SCons.Errors.InternalError, "The Platform SDK directory was not found in the registry or in the `MSSdk` environment variable."
InternalError: The Platform SDK directory was not found in the registry or in the `MSSdk` environment variable.
I don't know what the VS2003 VCToolkitInstallDir ENVVAR was pointing to to fix this.
With all that said, I just noticed that Anders said that I might also have to use an older version of scons as well with python2.7 so I suppose I'll spend some time investigating that (along with looking into #bdbaddog's solution).
-UPDATE 2-
it was the mstoolkit directive (see #Anders answer's comments)
I got it working after that while using py 2.7 for NSIS 3.0.4.
Now on to x64 build but that's a different story so I'll post a different question.
NSIS v3.04 does not support Python 3, you have to grab the latest source code from SVN. v3.05 is coming out soon with support for Python 3.
VS2012 is old enough that you should be able to use Python 2.7 and a older version of SCons as an alternative.
As a final alternative, you can try to apply this diff to v3.04.
The issue you're running into is twofold.
Python > 3.0 strings are no longer bytes. They are unicode
SCons which supports Python > 3.0 (SCons >3.0 supports Python 2.7 and Python > 3.5.0)
In order to support this Node()'s (SCons's way of representing files, directories, and values which feed into a build) now have two methods get_contents() and get_text_contents().
Since you're using Python 3.8.0, get_contents() will return bytes, which explains the error you've received.
The proper way to resolve it is to change this line:
for v in re.compile(r'^\\H\{[v]?(\S+)\}', re.M).finditer(File('#/Docs/src/history.but').get_contents()): # Try to parse the Halibut history file
to:
for v in re.compile(r'^\\H\{[v]?(\S+)\}', re.M).finditer(File('#/Docs/src/history.but').get_text_contents()): # Try to parse the Halibut history file
Please let me know if this doesn't resolve the issue.
Also, if you're willing to install Python 2.7 and reinstall SCons via
py -2.7 -mpip install scons
(Assuming you've install the py launcher when installing Python. Not sure if that's default with Python 3.8 and/or Python 2.7. If not then /python -m pip install scons. You might have to install pip as well. Once again not sure on the default for that.)
Then you can avoid changing the SConstruct file.
Hope this helps!

How do I distribute my Python 3.6 application with all dependencies like in SqueezeTool

I have a python application that I built on Kivy for the GUI, and I separated that file from the RNN model. I just import that file directly with:
from keras_network import Network
I tried using the official trick to deploying using pyinstaller, but that doesn't work, as my application crashes, when running the final .exe file generated. I even made appropriate changes to the .spec file.
Isn't there an easier way to package this application in Python 3.6? (like SqueezeTool, which is too old, and isn't working in Python 3.6)
Can I compile the python files to .pyc files and have all dependencies statically linked? And why is this still such a big pain, when Python is so popular?
Ok... I finally got it to work.
I came up with this solution after I implemented the whole project in PyQt5, and while trying to package it with PyInstaller.
Here is how I got it to work (for people who could have any problems later):
Used python 3.5
Install Windows 10 SDK for some missing files that should've been with MSVC 2015.
Install the dev version PyInstaller from:
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip --upgrade
Used the command to include my data files, as well as including hidden import h5py:
pyinstaller --add-data keras_model.h5;. --add-data TrainingData.txt;. --hidden-import=h5py --hidden-import=h5py.defs --hidden-import=h5py.utils --hidden-import=h5py.h5ac --hidden-import=h5py._proxy project-name.py
Then edited the .spec file generated. Added "from kivy.deps import sdl2, glew" without the quotes in the beginning of the file after the comment. Also added "*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)]," without the quotes in the COLLECT() function call as the 6th argument.
Then used the following command to rebuild using .spec file:
pyinstaller --add-data keras_model.h5;. --add-data TrainingData.txt;. --hidden-import=h5py --hidden-import=h5py.defs --hidden-import=h5py.utils --hidden-import=h5py.h5ac --hidden-import=h5py._proxy project-name.spec
Then the built application's executable was present in the 'dist\project-name\' directory. Double clicking the application lead to the application executing perfectly.
Hope this helps anyone stuck in the same place.

How can I get pylint to use python 3 in VS code?

I want pylint to use python3 for linting in Visual Studio code on Mac (which has both python 2.7 standard and python 3.6).
I've tried changing the path to the python interpreter as per How can I debug Python3 code in Visual Studio Code, to no avail. I keep getting python2 errors instead of python3 errors.
See example code for the problem.
Is there a way I can get pylint to recognize python3 errors?
Pick a xx.py in Visual Studio Coce(VSC)
In Status Bar Tap Python 2.7.10 like the [img1]
Choose python 3.x like [img2]
Command+Q quit VSC, then open VSC again
I finally got it working by installing python3 pylint from the console.
sudo python3 -m pip install -U pylint
The simple solution is to just change the first line of the file /home/user_name/.local/bin/pylint from #!/usr/bin/python2 to #!/usr/bin/python3
If you want more, you can rename this file to pylint2 and have a copy pylint3 where you change the first line to #!/usr/bin/python3.
Now to use pylint3 from command line you just need to type pylint3 instead of pylint.. also change the directory of pylinter in vscode to /home/user_name/.local/bin/pylint3
explanation
Ok this might be very late and the answer might not be the optimum, but I had the same issue.
By default the path to pylint is /home/user_name/.local/bin/pylint that is a simple python script working as the entry point to pylint.. even after installing pylint using pip3 this file is not changed and keeps directing to use python2 and therefore the packages installed by pip2 for python2.
So either have separate entry points for each pylint version, or modify this one manually to use the pylint package installed for python3.

cx_Freeze not found error-python

Ok, I am using python 3.4.3 and I think I downloaded the right file but when I go to python shell, it says No module named 'cx_Freeze'
I know there are plenty of questions like this but none of them helped. There was one I found using my exact same problem and version but even that did not work. I do not know what to do. I have put the file in the same place, I think anyways, as python is and I tried putting it on my desktop but still does not work. Any ideas?
faced a similar problem (Python 3.4 32-bit, on Windows 7 64-bit). After installation of cx_freeze, three files appeared in c:\Python34\Scripts:
cxfreeze
cxfreeze-postinstall
cxfreeze-quickstart
These files have no file extensions, but appear to be Python scripts. When you run python.exe cxfreeze-postinstall from the command prompt, two batch files are being created in the Python scripts directory:
cxfreeze.bat
cxfreeze-quickstart.bat
From that moment on, you should be able to run cx_freeze.
cx_freeze was installed using the provided win32 installer (cx_Freeze-4.3.3.win32-py3.4.exe). Installing it using pip gave exactly the same result.
Ok, I figured it out. So this is for all the future people have the same problem as I am. First, download pip. Then open a python shell and import pip. This is to make sure the download of pip was successful. Then go to the cx_Freeze website and for python 3.4.3, it will be the last one I think. It will say the version of cx_Freeze and then say the version of python which is 3.4.3 for me. That will download and then go to python shell and import cx_Freeze. It should work. Remember that you have to capitalize the "F" and have the code be exactly like this "cx_Freeze" but without the quotes. That is how I solved this problem with this exact python version.

Resources