Sphinx not using the right Python version inside virtual environments - python

I've created a virtual environment using both virtualenv and pipenv and in the both cases it seems that sphinx is not able to figure out the correct Python version. I have installed Python 2.7 and Python 3.8 in my global environment.
The error shows up when I try to use sphinx-apidoc + make html. I'm on a Windows 10 machine. Because I'm using type annotations, I get this error:
(venv) C:\Users\eug\Documents\learning\learning-pdoc\docs>make html
Running Sphinx v1.8.5
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 3 source files that are out of date
updating environment: 3 added, 0 changed, 0 removed
reading sources... [100%] sample_package
WARNING: autodoc: failed to import module u'core' from module u'sample_package'; the following exception was raised:
Traceback (most recent call last):
File "c:\python27\lib\site-packages\sphinx\ext\autodoc\importer.py", line 154, in import_module
__import__(modname)
File "C:\Users\eug\Documents\learning\learning-pdoc\sample_package\core.py", line 4
def sample_function2(a : Number, b : Number)->Number:
^
SyntaxError: invalid syntax
As you can see I'm currently on the virtual environment (venv). Calling python by itself correctly calls the right version. In order to execute what I want I need to call:
python -m sphinx.cmd.build -M html . .
Which is not ideal. Is there a way to fix this?

Related

module 'minisam' has no attribute 'DiagonalLoss'

I am using PyICP github repo. I built the Sophus from this commit (commit a0fe89a323e20c42d3cecb590937eb7a06b8343a) Reference.
I am using Ubuntu 22 and used virtual environment (venv with python version 3.7.14) to build the PyICP repo, minisam and Sophus repo.
Finally when I run the command python3 main_icp_slam.py it runs in this error.
(venv) shubham#shubhamubuntu:~/Lidar_Slam/minisam$ python3 main_icp_slam.py Traceback (most recent call last): File "main_icp_slam.py", line 50, in <module> PGM = PoseGraphManager() File "/home/shubham/Lidar_Slam/minisam/utils/PoseGraphManager.py", line 9, in __init__ self.prior_cov = minisam.DiagonalLoss.Sigmas(np.array([1e-6, 1e-6, 1e-6, 1e-4, 1e-4, 1e-4])) AttributeError: module 'minisam' has no attribute 'DiagonalLoss' (venv) shubham#shubhamubuntu:~/Lidar_Slam/minisam$ python3 main_icp_slam.py
The image view of this error is HERE
I am not sure is it caused by Sophus, Eigen, Venv or minisam.
Let me know if anymore information is needed.
Thanks, for any and all the help.
It is probably because you have multiple versions of python on your system and you have installed minisam on another python version. When you run cmake (for installing minisam) look at the version it shows for the python executable and also check your root python version (or environment that you are using), they should match.
If they don't match either make an environment with the python version your minisam is installed on or run your code as follows: (let say it is installed on python 3.6)
$ python3.6 main_icp_slam.py

Running an Nsight Systems report python script independently

I've tweaked a copy of one of the Nsight Systems report scripts (gpukernsum), and I now want to run it myself. So, I write:
./gpukernsum.py report.sqlite
This doesn't work; I get:
ERROR: Script 'gpukernsum.py' encountered an internal error.
$ ./gpukernsum.py report.sqlite
File "./gpukernsum.py", line 40
"""
^
SyntaxError: invalid syntax
I know this is because f"""whatever""" is Python-3 syntax, so I change the script's hash-bang line from:
#!/usr/bin/env python
to:
#!/usr/bin/env python3
and now I get:
$ ./gpukernsum.py report.sqlite
Traceback (most recent call last):
File "/path/to/./gpukernsum.py", line 7, in <module>
import nsysstats
ModuleNotFoundError: No module named 'nsysstats'
So I added the relevant directory to the lookup path:
export PYTHONPATH="$PYTHONPATH:/opt/nvidia/nsight-systems/2022.1.1/host-linux-x64/python/lib"
and now I get:
$ ./gpukernsum.py report.sqlite
near "WITH": syntax error
... and I'm stuck. The relevant area of the code is:
and not a percentage of the application wall or CPU execution time.
"""
query_stub = """
WITH
summary AS (
SELECT
coalesce({NAME_COL_NAME}, demangledName) AS nameId,
i.e. the "WITH" is part of a string literal which is an SQL query. So, what's the problem? Is Python complaining? Is sqlite complaining?
Note:
Nsight Systems 2022.1.1
CentOS 7
I'm using the original gpukernsum.py code - I have not made any changes to it (other than as described above).
My system has Python 3.9.1 for python3.
A workaround answer:
Nsight Systems bundles its own version of Python, with lib and bin directories.
If you run your script with this specific version, having set PYTHONPATH as described in your question - then the script will work. It's what Nsight itself does, after all.

Why does yocto scipy recipe require python3 explicitly set? How?

I have a recipe to build scipy which parses fine and bitbake starts building but the python3
version requirement is not met. It exits with
| DEBUG: Executing shell function do_configure
| Traceback (most recent call last):
| File "setup.py", line 31, in <module>
| raise RuntimeError("Python version >= 3.5 required.")
| RuntimeError: Python version >= 3.5 required.
| WARNING: exit code 1 from a shell command.
| ERROR: Function failed: do_configure (log file is located at /home/marius/mender-qemu/build/tmp/work/core2-64-poky-linux/python3-scipy/1.4.1-r0/temp/log.do_configure.30478)
I successfully built other python3 packages which can be imported in the running image. You can also see from the path that python3 is used and the image runs on python3.5. I'm using thud.
For the sake of completion here is the recipe. I also tried explicitly adding dependencies (numpy) but that did not have any effect.
SUMMARY = "Scipy summary to be filled"
DESCRIPTION = "Scientific computing"
PYPI_PACKAGE = "scipy"
LICENSE = "BSD"
LIC_FILES_CHKSUM = "file://LICENSE.txt;md5=011ccf01b7e0590d9435a864fc6a4d2b"
SRC_URI[md5sum] = "3a97689656f33f67614000459ec08585"
SRC_URI[sha256sum] = "dee1bbf3a6c8f73b6b218cb28eed8dd13347ea2f87d572ce19b289d6fd3fbc59"
This is the python-scipy.inc
inherit setuptools3 distutils
require python-scipy.inc
Also, I tried to add inherit python3native without effect.
My question is: how can I explicitly set python3 to build this recipe?
The simple and obvious solution was to inherit distutils3 instead of inherit distutils.
NOTE: A python-scipy recipe that worked out of the box for me can be found here: https://github.com/gpanders/oe-scipy
Nice job gpanders!
My guess is that you run a python script setup.py as part of your build that requires python3 on your host(the system that build Yocto).
You can install it like this:
sudo apt-get install python3

gdal_merge.py not working after gdal and it python bindings have been installed

I installed Python 3.4.0 64 bit and gdal file release-1400-x64-gdal-1-11-1-mapserver-6-4-1.zip from http://www.gisinternals.com/release.php. I found the binding from http://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal and the filename is GDAL-1.11.2-cp34-none-win_amd64. I successfully install these files and import gdal. However, when I run the following command within the Python IDE to merge files 1 2 and 3, I got an error
>>> gdal_merge.py -o out.tif 1.tif 2.tif 3.tif
File "<console>", line 1
gdal_merge.py -o out.tif 1.tif 2.tif 3.tif
^
SyntaxError: invalid syntax
I specifically check to see if I can import gdal_merge as below
>>> import gdal_merge
and it was ok.
I appreciate if anybody could help with this issue.
gdal_merge.py is part of the GDAL utilities which are executed from the command line, not from within a Python IDE or another Python script.
Just open a command line (cmd) and type:
python gdal_merge.py -o out.tif 1.tif 2.tif 3.tif
Depending on your environment variables and whether you included GDAL in your Path variable you might need to specificy the full path to gdal_merge.py and/or can leave out python at the beginning of the call.

Syntax error when installing the spkg package of wxPython on Sage

When I want to install the package wxPython-2.8.7.1.spkg from here
in the terminal of Sage it gives me a syntax error. What i write in Sage terminal and the result are as follow:
sage: sage -i wxPython-2.8.7.1.spkg
------------------------------------------------------------
File "<ipython console>", line 1
sage -i wxPython-RealNumber('2.8').gen(7).1.spkg
^
SyntaxError: invalid syntax
I also use the direct address of the package but the result was the same:
sage: sage -i http://www.sagemath.org/packages/experimental/wxPython-2.8.7.1.s>
------------------------------------------------------------
File "<ipython console>", line 1
sage -i http://www.sagemath.org/packages/experimental/wxPython-RealNumber('2.8').gen(7).1.spkg
^
SyntaxError: invalid syntax
I also downloaded the package and used the local address but the result was the same.
You need to do this from the command line before starting Sage. Otherwise you can use
sage: install_package("wxPython")
which is currently downloading for me... and then failed:
checking for GTK+ - version >= 2.0.0... no
*** Could not run GTK+ test program, checking why...
*** The test program failed to compile or link. See the file config.log for the
*** exact error that occured. This usually means GTK+ is incorrectly installed.
configure: error:
The development files for GTK+ were not found. For GTK+ 2, please
ensure that pkg-config is in the path and that gtk+-2.0.pc is
installed. For GTK+ 1.2 please check that gtk-config is in the path,
and that the version is 1.2.3 or above. Also check that the
libraries returned by 'pkg-config gtk+-2.0 --libs' or 'gtk-config
--libs' are in the LD_LIBRARY_PATH or equivalent.
Error configure wx widgets.
real 0m13.972s
user 0m2.791s
sys 0m5.232s
************************************************************************
Error installing package wxPython-2.8.7.1
************************************************************************
Along those lines, here is what it says at the list of experimental spkgs, of which this is one:
These are EXPERIMENTAL! They probably won't work at all for you! Use at your own risk! Many of these have never been successfully built on any platform!
So buyer beware!

Categories