Sphinx make file may be using wrong docutils file - python

I am following this tutorial on how to get started with sphinx documentation for python.
On my mac, I run the make command
$ make html
(as instructed around minute 09:25 in the video), however I get the error
Exception occurred:
File "/Users/me/anaconda/lib/python2.7/site-packages/docutils/writers/html4css1/__init__.py", line 21, in <module>
from docutils.writers import _html_base
ImportError: cannot import name _html_base
From the error, it seems the make file is using an older python 2.7 version of docutils that came installed with the Mac. I believe the make file should be using a more recent version of docutils located here
/Users/me/anaconda/pkgs/sphinx-1.6.3-py36hcd1b3e7_0/lib/python3.6/site-packages/sphinx/utils/docutils.py
This file does not import the package _html_base, which seems to be the problem with the python 2.7 version of the docutils file.
How can I "point the make file to use the python 3.6 docutils"? if that question makes sense. Or is there a better way to fix this?

The problem is that you installed sphinx via the command pip install -U sphinx where pip points to Mac's Python2.7
In order to overcome this, you need to pip3 install -U sphinx (if you have a Python3.x available).

Related

How do I update python on my Raspberry Pi to at least 3.6?

As some brief background information: I was origianlly trying to use Miniconda (with conda) to install dependencies that I need for my project on my Raspberry Pi. After trying to use Conda to install the SimpleAudio package, I got an error saying that it did not exist, therefore I proceeded to install this through Pip. Pip found the correct package although I get the following error message:
pi#raspberrypi:~ $ pip install simpleaudio
Traceback (most recent call last):
File "/home/pi/miniconda3/bin/pip", line 7, in <module>
from pip._internal.cli.main import main
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/cli/main.py", line 10, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
from pip._internal.cli import cmdoptions
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/cli/cmdoptions.py", line 28, in <module>
from pip._internal.models.target_python import TargetPython
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/models/target_python.py", line 4, in <module>
from pip._internal.utils.misc import normalize_version_info
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/utils/misc.py", line 20, in <module>
from pip._vendor import pkg_resources
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_vendor/pkg_resources/__init__.py", line 92, in <module>
raise RuntimeError("Python 3.5 or later is required")
RuntimeError: Python 3.5 or later is required
It seems I need to update Python, although when I print the verion on Spyder IDE, it says I am already using 3.7.
Have I caused some sort of mismatch between what version my IDE is using and what the default process the terminal uses to look up the version? I noticed that it is looking for the Python version under Miniconda. If I can update If so is there a fix for this?
Please as me for more information if required (I am fairly new to stack overflow).
UPDATE:
I have been able to install the updated version of Python to 3.6 using the following instructions:
https://stackoverflow.com/a/56852714/12361146
This generally solves the scope of this question in terms of how I update Python, but I am still confused as to why Spyder IDE uses a more up-to-date version of Python whereas the terminal shows otherwise.
To answer the question of why Spyder reports a more up-to-date version of Python, here's the reason. The default versions of Python that are installed with Raspbian are 2.7 and 3.5, located in the /usr/bin/ directory. When you install Spyder, however (either independently, or more commonly, using conda), it includes its own installation of Python, which it is configured to use in the IDE, and which is located in a different directory. Hence when you compare the versions, first by entering python3 --version on the command line, and then print(sys.executable) from the Spyder IDE, they're different.
Now the issue with using pip alongside conda for updating the Spyder installation of Python is that it has the potential to mess it up quite badly, so avoid that unless you really know what you're doing. From code you posted above, you have avoided that, though, since that will have impacted the default Raspbian installation of Python, not the Spyder one. Upgrading the latter version should be done using Conda, not pip.
Hopefully you're now all up and running.
You can install newer versions of python using the package manager apt or apt-get.
Start by getting up-to-date package definitions.
$ sudo apt-get update
Then you can show details about the python3 package.
$ apt-cache show python3
When I run that now I get "Version: 3.7.3-1".
To install the python3 package and all its dependencies.
$ sudo apt-get install python3
You will still need to type python3 and pip3 when you run the commands because you are not replacing the built-in python 2.7.
Try these commands to see what you get
$ python --version
$ python3 --version
If you want to change the default python to python3 then have a look at this answer How to change the default python version in Raspberry Pi

ModuleNotFoundError: No module named 'ruamel'

I'm using a Kubernetes inventory builder script found here: https://github.com/kubernetes-sigs/kubespray/blob/master/contrib/inventory_builder/inventory.py
On line 36, the ruamel YML library is imported using the code from ruamel.yaml import YAML. This library can be found here: https://pypi.org/project/ruamel.yaml/
On my OSX device (Mojave 10.14.3), if I run pip list, I can clearly see the most up to date version of ruamel.yaml:
If I run pip show ruamel.yaml, I get the following output:
I'm running the script with this command: CONFIG_FILE=inventory/mycluster/hosts.ini python3 contrib/inventory_builder/inventory.py 10.0.0.1 10.0.0.2 10.0.0.4 10.0.0.5
Bizarrely, it returns the following error:
Traceback (most recent call last):
File "contrib/inventory_builder/inventory.py", line 36, in <module>
from ruamel.yaml import YAML
ModuleNotFoundError: No module named 'ruamel'
I have very little experience with Python, so don't understand how this could be failing. Have I installed the library incorrectly or something? From the documentation on the ruamel.yml project page, it looks like the script is calling the library as it should be.
Thanks in advance
In my case, I was installing this with pip3 install ruamel.yaml, and it was puting the package in /usr/local/lib/python3.9/site-packages/, but the python3 binary on the machine was pinned to Python 3.7, so trying to import that module was sending the ModuleNotFoundError message.
What helped to fix this, was to install the module with python3 -m pip install ruamel.yaml, running pip via the python3 binary makes sure it runs on the same version, in this case 3.7, and gets installed via the correct version number site-packages.
pip is set to point to the Python 2 installation. To install the library under Python 3, do pip3 install ruamel.yml.
you're using python 3 and want to use the package that is with python 2. Go to the directory where your python 3 is, navigate to Scripts and use the pip in there to install the needed library.
This helped me (adding version number to python):
CONFIG_FILE=inventory/mycluster/hosts.yaml python3.6 contrib/inventory_builder/inventory.py ${IPS[#]}
[python 3.10.x].
There is no package called ruamel.yaml
what worked is pip install ruamel-yaml

invalid syntax when run pylint

the following is the stack trace, please suggest
my python version is 2.7
-----------------
pylint
Traceback (most recent call last):
File "E:\Python27\Scripts\pylint-script.py", line 11, in <module>
load_entry_point('pylint==2.0.0', 'console_scripts', 'pylint')()
File "E:\Python27\lib\site-packages\pylint-2.0.0-py2.7.egg\pylint\__init__.py"
, line 17, in run_pylint
from pylint.lint import Run
File "E:\Python27\lib\site-packages\pylint-2.0.0-py2.7.egg\pylint\lint.py", li
ne 75, in <module>
import astroid
File "E:\Python27\lib\site-packages\astroid-2.0.1-py2.7.egg\astroid\__init__.p
y", line 59, in <module>
from astroid.exceptions import *
File "E:\Python27\lib\site-packages\astroid-2.0.1-py2.7.egg\astroid\exceptions
.py", line 13, in <module>
from astroid import util
File "E:\Python27\lib\site-packages\astroid-2.0.1-py2.7.egg\astroid\util.py",
line 148
yield from islice(iterator, size)
^
SyntaxError: invalid syntax
my python version is 2.7
pylint 2.0.0 requires at least Python 3.4.1
The last version that supported Python 2.7 was 1.9.2. So, your fix is to downgrade to 1.9.2.
The specific error message you're seeing is because yield from was added to the language in Python 3.3, so code that uses it can't run in 2.7. But there are probably lots of other errors. After all, the only reason developers drop 2.7 support is so they can use new language features.
If you install it with pip install pylint or py -m pip install pylint using Python 2, it should automatically install 1.9.2 instead of 2.0.0—or, failing that, the installation should fail instead of appearing to succeed. (When I test it myself, that's exactly what happens.)
However, installing with an old version of pip, might cause this problem. If so, upgrade your pip and setuptools. (You definitely want at least pip 10 and setuptools 30… but generally you want the latest version available, so just let it do that.)
py -m pip install --upgrade pip setuptools
If that was your problem, you should have seen a warning, like You are using pip version 6.0, however version 18.0 is available. That warning doesn't look hugely important, but it is—especially if you're staying on 2.7 (or, similarly, if you like to follow the bleeding edge and install beta versions of Python).
Installing with easy_install can definitely cause this. If that's your problem, just stop using easy_install and start using pip.
If you installed it manually instead of by using pip, then you have to do the version checking manually as well. If you have a good reason for doing that, download 1.9.2 and install that manually instead.
At any rate, however you got thing into this situation, you should be able to fix it by uninstalling pylint and then running:
py -m pip install pylint==1.9.2
1. According to its own documentation, it specifically supports 3.4, 3.5, and 3.6. It may also support 3.7 despite saying it doesn't—later versions definitely do, and of course future versions will support even newer versions of Python. But definitely not 2.7.

Installing and importing Python Modules onto OS X

I've been trying for a couple of hours already. It seems IDLE can't find any third-party module. I am a Python beginner.
Here is some info about my system:
OSX version: 10.11.5
python version: Python 2.7, Python 3.4, Python 3.5
The initial installation using pip (among other methods) seems to work fine. When I repeat the installation, terminal responds with:
Requirement already satisfied (use --upgrade to upgrade): pyperclip in
./anaconda/lib/python3.4/site-packages
However, when I go to IDLE (Python 3.4) and try to import the module, IDLE responds with:
Traceback (most recent call last): File "", line 1, in
import pyperclip ImportError: No module named 'pyperclip'
I have read that it may have something to do with my PATH or some virtual environment. I’ll be frank, I’m not sure what to make of these as they seem beyond my current ability.
This inability to import modules is becoming an almost insurmountable roadblock to advancing with Python. If you can offer any ideas on what I can do or can ELI5 the solution, I am forever in your debt?
It seems you are using conda, but you are trying to install the pyperclip module with pip. Have you tried running conda install pyperclip?
As stated here:
Because Conda introduces a new packaging format, you cannot use pip and Conda interchangeably; pip cannot install the Conda package format. You can use the two tools side by side but they do not interoperate either.

How do I install Python packages/ wxPython on Mac OSX?

I'm very new to python and any non-basic computer functions in general, but I'm having a very basic problem and I can't figure out how to fix it. Any time I download a module from the internet and try to import it in python, I get an error message. For example, I just downloaded wxPython after being instructed to do so on a tutorial program for Python I've been using, and after entering "import wx" I got:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
import wx
ImportError: No module named wx
How do I fix this so that python can find modules I download?
Thanks!!
Python version 2.7.3, and I downloaded wxPython from the download link on the website. Another thing I noticed: whenever I type in python setup.py install in the Terminal, I get:
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
can't open file 'setup.py': [Errno 2] No such file or directory
Which seems to be another huge problem?
There are a few things you need to do to actually debug this:
Run python and check what version you are running.
type where python and figure out if you have multiple versions of python running at once.
With pip or easy_install, read the output to check where they are installing packages. It's somewhat likely that they are installing to the system-wide Python 2.6, as opposed to the version that you want it to be installed to (Python 2.7).
If you find any packages installed in the wrong place with 3, uninstall them with pip uninstall <packagename> and then specifically reinstall them to 2.7 with easy_install-2.7 or pip-2.7 install. If you don't see the option for easy_install-2.7 or pip-2.7, you need to install distribute and run its setup.py file with the specific version of Python you are using.
Make sure you are actually in the directory when running setup.py. For example, to install distribute, you need to cd into the appropriate directory to install.
Finally, a separate note: it's far easier to install packages with easy_install or pip, as opposed to downloading them separately. You should try doing that first. Again, distribute has more info.

Categories