Removing and reinstalling Python-Sphinx on Windows - python

I am trying to use Python (3.8) and Sphinx (3.3.1) to build a documentation in HTML. However, the sphinx-build command gives me the following error:
C:\Users\Me\Dropbox\Kuchen>sphinx-build -b html source build
Running Sphinx v3.3.1
loading pickled environment... done
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 1 source files that are out of date
updating environment: 0 added, 1 changed, 0 removed
reading sources... [100%] kaesekuchen
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] kaesekuchen
generating indices... genindex done
writing additional pages... search done
copying static files... WARNING: Failed to copy a file in html_static_file: c:\users\me\appdata\local\programs\python\python38\lib\site-packages\sphinx\themes\basic\static/jquery-3.5.1.js: PermissionError(13, 'Permission denied')
WARNING: Failed to copy a file in html_static_file: c:\users\me\appdata\local\programs\python\python38\lib\site-packages\sphinx\themes\basic\static/jquery.js: PermissionError(13, 'Permission denied')
done
copying extra files... done
dumping search index in English (code: en)... done
dumping object inventory... done
build succeeded, 2 warnings.
However,
The HTML file kaesekuchen in build is not updated/changed.
The folder c:\users\me\appdata\local\programs\python\python38\lib\site-packages\sphinx does not exist.
The latter is my fault, because I deleted it in file explorer, but only because I encountered the exact same error before, and hoped that deleting and re-installing Sphinx would solve it.
Instead, the commands pip uninstall sphinx and subsequent pip install -U sphinx do not change anything in that folder, and the latter only gives the following upbeat output despite the following output:
Microsoft Windows [Version 10.0.18363.1198]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\Users\me>pip uninstall sphinx
Found existing installation: Sphinx 3.3.1
Uninstalling Sphinx-3.3.1:
Would remove:
c:\users\me\appdata\local\programs\python\python38\lib\site-packages\sphinx-3.3.1.dist-info\*
c:\users\me\appdata\local\programs\python\python38\lib\site-packages\sphinx\*
c:\users\me\appdata\local\programs\python\python38\scripts\sphinx-apidoc.exe
c:\users\me\appdata\local\programs\python\python38\scripts\sphinx-autogen.exe
c:\users\me\appdata\local\programs\python\python38\scripts\sphinx-build.exe
c:\users\me\appdata\local\programs\python\python38\scripts\sphinx-quickstart.exe
Proceed (y/n)? y
Successfully uninstalled Sphinx-3.3.1
C:\Users\me>pip install -U sphinx
Collecting sphinx
Using cached Sphinx-3.3.1-py3-none-any.whl (2.9 MB)
Requirement already satisfied, skipping upgrade: docutils>=0.12 in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (from sphinx) (0.16)
Requirement already satisfied, skipping upgrade: sphinxcontrib-serializinghtml in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (from sphinx) (1.1.4)
Requirement already satisfied, skipping upgrade: snowballstemmer>=1.1 in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (from sphinx) (2.0.0)
Requirement already satisfied, skipping upgrade: alabaster<0.8,>=0.7 in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (from sphinx) (0.7.12)
Requirement already satisfied, skipping upgrade: setuptools in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (from sphinx) (41.2.0)
Requirement already satisfied, skipping upgrade: colorama>=0.3.5; sys_platform == "win32" in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (from sphinx) (0.4.4)
Requirement already satisfied, skipping upgrade: sphinxcontrib-jsmath in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (from sphinx) (1.0.1)
Requirement already satisfied, skipping upgrade: babel>=1.3 in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (from sphinx) (2.9.0)
Requirement already satisfied, skipping upgrade: imagesize in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (from sphinx) (1.2.0)
Requirement already satisfied, skipping upgrade: sphinxcontrib-devhelp in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (from sphinx) (1.0.2)
Requirement already satisfied, skipping upgrade: sphinxcontrib-qthelp in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (from sphinx) (1.0.3)
Requirement already satisfied, skipping upgrade: Jinja2>=2.3 in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (from sphinx) (2.11.2)
Requirement already satisfied, skipping upgrade: sphinxcontrib-applehelp in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (from sphinx) (1.0.2)
Requirement already satisfied, skipping upgrade: requests>=2.5.0 in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (from sphinx) (2.25.0)
Requirement already satisfied, skipping upgrade: packaging in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (from sphinx) (20.4)
Requirement already satisfied, skipping upgrade: sphinxcontrib-htmlhelp in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (from sphinx) (1.0.3)
Requirement already satisfied, skipping upgrade: Pygments>=2.0 in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (from sphinx) (2.7.2)
Requirement already satisfied, skipping upgrade: pytz>=2015.7 in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (from babel>=1.3->sphinx) (2020.4)
Requirement already satisfied, skipping upgrade: MarkupSafe>=0.23 in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (from Jinja2>=2.3->sphinx) (1.1.1)
Requirement already satisfied, skipping upgrade: urllib3<1.27,>=1.21.1 in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (from requests>=2.5.0->sphinx) (1.26.2)
Requirement already satisfied, skipping upgrade: idna<3,>=2.5 in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (from requests>=2.5.0->sphinx) (2.10)
Requirement already satisfied, skipping upgrade: certifi>=2017.4.17 in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (from requests>=2.5.0->sphinx) (2020.11.8)
Requirement already satisfied, skipping upgrade: chardet<4,>=3.0.2 in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (from requests>=2.5.0->sphinx) (3.0.4)
Requirement already satisfied, skipping upgrade: six in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (from packaging->sphinx) (1.15.0)
Requirement already satisfied, skipping upgrade: pyparsing>=2.0.2 in c:\users\me\appdata\local\programs\python\python38\lib\site-packages (from packaging->sphinx) (2.4.7)
Installing collected packages: sphinx
Successfully installed sphinx-3.3.1
But the folder c:\users\me\appdata\local\programs\python\python38\lib\site-packages\sphinx\ is still not there.
I even tried to run a new Sphinx project from scratch, using sphinx-quickstart:
For a list of supported codes, see
https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-language.
> Project language [en]: en
Creating file C:\Users\me\Dropbox\Kuchentest\source\conf.py.
Creating file C:\Users\me\Dropbox\Kuchentest\source\index.rst.
Creating file C:\Users\me\Dropbox\Kuchentest\Makefile.
Creating file C:\Users\me\Dropbox\Kuchentest\make.bat.
Finished: An initial directory structure has been created.
You should now populate your master file C:\Users\me\Dropbox\Kuchentest\source\index.rst and create other documentation
source files. Use the Makefile to build the docs, like so:
make builder
where "builder" is one of the supported builders, e.g. html, latex or linkcheck.
But despite this output, there are no such files or source folder being created.
What can I do to cleanly reset my Sphinx installation and get my documentation to run again?

Solving this requires a somewhat awkward explanation that is simultaneously dependent on: operating system (Windows), your particular installation, and how you are executing Sphinx.
On Windows you can have several Python installations in different places (depending...):
One usual location is C:\Program Files\Python3x.
The pre-configured default path is C:\Users\me\AppData\Local\Programs\Python\Python3.x\. I find this inconvenient because it's located deep away from the root.
The currently prevalent way of extending a Python installation is using a virtual environment (venv).
Your venv, wherever you decided to place it. (Using a venv is considered the "de facto" best practice.)
At one point in time, you set PYTHONPATH as an environment variable on Windows and it's in those paths that Windows will look for your Python installations. Notice the rules for Module Search Path. The problem now becomes that if you have more than one Python installation set on your Path, Windows will also look for libraries in other installations...
(A general note about Python installations on Windows is necessary. Sometime in 2019 Microsoft included Python with Windows - as noted by a prominent SO user in this answer, and referred in the documentation. Around that time there was a Windows bug that required environment variables to be set with the administrator account - I can't find a reference but it's mentioned somewhere on SO. Meaning it's advisable to make your separate installation of Python and set environment variables as admin.)
Having said that, the problem you are describing has several aspects (take special notice of the terminal you are using):
The first warning in your sphinx-build indicates Sphinx is trying to read files from your user account installation (point 2 above). The problem is the terminal where you are executing sphinx-build does not have permission to read from the user account installation directories, because the terminal is being run under a different user account or because the account installation paths aren't set with read permission... Having said that, reconsider the warnings:
copying static files... WARNING: Failed to copy a file in html_static_file: c:\users\me\appdata\local\programs\python\python38\lib\site-packages\sphinx\themes\basic\static/jquery-3.5.1.js: PermissionError(13, 'Permission denied')
WARNING: Failed to copy a file in html_static_file: c:\users\me\appdata\local\programs\python\python38\lib\site-packages\sphinx\themes\basic\static/jquery.js: PermissionError(13, 'Permission denied')
It may also be the case you deleted Sphinx from your account installation and the files/paths simply aren't there.
Next when you try to reinstall Sphinx using pip it is not entirely clear if it's an outdated cache issue, or if pip is finding Sphinx in another installation on your PYTHONPATH... It may be the case that Sphinx is installed and the terminal simply hasn't read/write permission (depends what user account invoked the terminal), or the directory may be hidden in the file explorer...
What can I do to cleanly reset my Sphinx installation and get my documentation to run again?
Your Python base installations (points 1 and 2 above) are only supposed to be written to for system or user wide changes (not for a particular project change).
It is strongly recommended that you use a venv. (If you haven't before this would be the right time to consider doing so because it's the easiest and cleanest solution). This may initially seem confusing because historically there have been several virtual-environments for Python. Currently venv is the most commonly cited solution and using it is simple, your IDE should have a built-in UI to help you create it with a couple of clicks.
A venv is a Python environment that extends your base installation, it avoids a need to change your base installation when you have to make project specific changes (like having Sphinx installed, should ideally be on the venv not the base installation.)
Finally, when you run Sphinx from the terminal it's advisable to activate your venv on the terminal, otherwise the Python installation that is executed may depend on the user account that invoked the terminal.

Related

xarray ERROR : ValueError: did not find a match in any of xarray's currently installed IO backends

I am trying to open a RINEX dataset using xarray. Although I have already installed both 'netcfd4' and 'scipy', I am getting the following value error.
ValueError: did not find a match in any of xarray's currently installed IO backends ['netcdf4', 'scipy']. Consider explicitly selecting one of the installed engines via the ``engine`` parameter, or installing additional IO dependencies, see:
http://xarray.pydata.org/en/stable/getting-started-guide/installing.html
http://xarray.pydata.org/en/stable/user-guide/io.html
When I again try to install scipy and netcdf4 i get the following messeage.
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: netcdf4 in c:\users\sdasgupta.student\appdata\roaming\python\python39\site-packages (1.6.1)
Requirement already satisfied: numpy>=1.9 in c:\programdata\anaconda3\lib\site-packages (from netcdf4) (1.21.5)
Requirement already satisfied: cftime in c:\users\sdasgupta.student\appdata\roaming\python\python39\site-packages (from netcdf4) (1.6.2)
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: scipy in c:\users\sdasgupta.student\appdata\roaming\python\python39\site-packages (1.9.3)
Requirement already satisfied: numpy<1.26.0,>=1.18.5 in c:\programdata\anaconda3\lib\site-packages (from scipy) (1.21.5)
I have uninstall and install xarray, scipy and netcdf4 but still it is giving me the same error.
Check if the file exists.
Per this answer on xarray github: https://github.com/pydata/xarray/issues/6335#issuecomment-1199282081
Since folks have asked questions since this was closed (and I had a similar issue), this ValueError exception can be raised in a misleading way if the file being specified does not exist. The exception implies that it is a file format error, but it may just not exist.

Python: already install package but can't use (sklearn)

I have already installed sklearn and scikit-learn, the version of sklearn showed 0.0(use pip show instr.)
I've tried many ways to install or update packages, but when I ran the code it shows:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import sklearn
ModuleNotFoundError: No module named 'sklearn'
when I install again, it shows:
Requirement already satisfied: sklearn in c:\users\user\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (0.0)
Requirement already satisfied: scikit-learn in c:\users\user\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from sklearn) (1.0.2)
Requirement already satisfied: numpy>=1.14.6 in c:\users\user\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from scikit-learn->sklearn) (1.22.3)
Requirement already satisfied: scipy>=1.1.0 in c:\users\user\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from scikit-learn->sklearn) (1.8.0)
Requirement already satisfied: threadpoolctl>=2.0.0 in c:\users\user\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from scikit-learn->sklearn) (3.1.0)
Requirement already satisfied: joblib>=0.11 in c:\users\user\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (from scikit-learn->sklearn) (1.1.0)
can anyone tell me how to deal with it?
thanks!!!
You can check whether the virtual environment installed sklearn is consistent with the one used for your code.
thanks for everyone!
I found that there was the error on the environment variables, it links to old version of python that i havn't deleted, I reinstall python and set the right path, and it works!
You can check which environment you installed that package? Example, with Miniconda, and if I have more than 1 env then I will switch to the specific env, and activate it and install lib.
Then you need to check what env you setup in your development tool (ex: Visual Code).

ModuleNotFoundError: No module named 'requests' - can not seem to solve in VS Code (Win 10)

I have looked at similar errors and the fixes I tried have not removed this error (yet).
Package Version
-------------- ---------
beautifulsoup4 4.9.2
certifi 2020.6.20
chardet 3.0.4
idna 2.10
lxml 4.5.2
pip 20.2.3
requests 2.24.0
setuptools 49.2.1
soupsieve 2.0.1
urllib3 1.25.10
There's my current installs which I got from the terminal in VS Code. So, from what I can see, it is all there.
When I run from inside VS Code (the play button top right) I get this error:
[local address of file], line 3, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
Further information *edit
I did install requests this way from the VS Code Terminal window:
python -m pip install requests
The output states:
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: requests in c:\users\[user]\appdata\roaming\python\python38\site-packages (2.24.0)
Requirement already satisfied: idna<3,>=2.5 in c:\users\[user]\appdata\roaming\python\python38\site-packages (from requests) (2.10)
Requirement already satisfied: chardet<4,>=3.0.2 in c:\users\[user]\appdata\roaming\python\python38\site-packages (from requests) (3.0.4)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\[user]\appdata\roaming\python\python38\site-packages (from requests) (1.25.10)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\[user]\appdata\roaming\python\python38\site-packages (from requests) (2020.6.20)
Any ideas on fixing this or a set of routine troublecheckers? Thanks kindly
You need to select the python interpreter to be the same of your current environment.
do
which python
/your_path/bin/python
That will give you the path, make sure the Python interpreter on your left button (at VSC) matches the same path, if not make it match.

Can't use pip3 modules: ModuleNotFoundError

I leveraged homebrew to install python3 and now I cannot run modules I install with the associated pip3 binary.
from blackduck.HubRestApi import HubInstance
username = "sysadmin"
password = "your-password"
urlbase = "https://ec2-34-201-23-208.compute-1.amazonaws.com"
hub = HubInstance(urlbase, username, password, insecure=True)
Running python3 blackduck.py Results in :
ModuleNotFoundError: No module named 'blackduck.HubRestApi'; 'blackduck' is not a package
Proof of package:
$pip3 install blackduck
Requirement already satisfied: blackduck in /usr/local/lib/python3.7/site-packages (0.0.25)
Requirement already satisfied: requests in /usr/local/lib/python3.7/site-packages (from blackduck) (2.21.0)
Requirement already satisfied: idna<2.9,>=2.5 in /usr/local/lib/python3.7/site-packages (from requests->blackduck) (2.8)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/site-packages (from requests->blackduck) (2019.3.9)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in /usr/local/lib/python3.7/site-packages (from requests->blackduck) (1.24.3)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.7/site-packages (from requests->blackduck) (3.0.4)
help('modules') -> contains blackduck
$pip3 list | grep blackduck
blackduck 0.0.25
I've tried to create a virtual environment, to no avail. I also tried adding /usr/local/lib/python3.7/site-packages to my $PYTHONPATH env variable. Thanks in advance!
Don't call your own python script the same as a python module or package - it picks itself up!
From the search-path documentation:
When a module named spam is imported, the interpreter first searches
for a built-in module with that name. If not found, it then searches
for a file named spam.py in a list of directories given by the
variable sys.path. sys.path is initialized from these locations:
The directory containing the input script (or the current directory
when no file is specified).
PYTHONPATH (a list of directory names, with the same syntax as the shell variable PATH).
The installation-dependent default.
So, all things being equal, the current directory is searched first.
Call it anything else, like my_blackduck.py. I recommend you use a homegrown prefix, maybe a project-code followed by something like an underscore, for development scripts so that you don't repeat the problem.

Could not install packages due to an EnvironmentError: [Errno 2] No Such file or directory

this is what I'm using to install packages, the only one that works is requests
pip._internal.main(['install', 'requests'])
pip._internal.main(['install', 'lxml'])
pip._internal.main(['install', 'cssselect'])
pip._internal.main(['install', 'selenium'])
this is the error message that i get in the console
Requirement already satisfied: requests in c:\users\user\appdata\local\programs\python\python37-32\lib\site-packages (2.20.1)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\users\user\appdata\local\programs\python\python37-32\lib\site-packages (from requests) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\user\appdata\local\programs\python\python37-32\lib\site-packages (from requests) (2018.11.29)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in c:\users\user\appdata\local\programs\python\python37-32\lib\site-packages (from requests) (1.24.1)
Requirement already satisfied: idna<2.8,>=2.5 in c:\users\user\appdata\local\programs\python\python37-32\lib\site-packages (from requests) (2.7)
Collecting lxml
Using cached https://files.pythonhosted.org/packages/43/c7/e088bf0f4f81e6b366cc2de12939c559b588b9525ad76215d122e69151ed/lxml-4.2.5-cp37-cp37m-win32.whl
Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: 'C:\\Users\\user\\AppData\\Local\\Temp\\pip-req-tracker-047sxufq\\9dca403282533c33ca73fe9ecbdb1b605aeffa273ec0704ef517f834'
Collecting cssselect
Using cached https://files.pythonhosted.org/packages/7b/44/25b7283e50585f0b4156960691d951b05d061abf4a714078393e51929b30/cssselect-1.0.3-py2.py3-none-any.whl
Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: 'C:\\Users\\user\\AppData\\Local\\Temp\\pip-req-tracker-047sxufq\\e5cecb9a9f004e9bd84aa92925e0dc6e8458127d14eb08f37c4e2d0f'
Collecting selenium
Using cached https://files.pythonhosted.org/packages/80/d6/4294f0b4bce4de0abf13e17190289f9d0613b0a44e5dd6a7f5ca98459853/selenium-3.141.0-py2.py3-none-any.whl
Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: 'C:\\Users\\user\\AppData\\Local\\Temp\\pip-req-tracker-047sxufq\\b3025a26893a7657747ef91c7e8a7d138021b8a645639c56cd0046c5'
i'm fairly new to python and just coding in general, i don't really know what these errors mean, and i couldn't find anything on google that i understood, so any help at all would be appreciated.
this is in visual studio code and on python 3.7.1
I know this is coming late, but I guess this will help someone else who is facing a similar issue.
In the path:
C:\\Users\\user\\AppData\\Local\\Temp\\pip-req-tracker-047sxufq\\b3025a26893a7657747ef91c7e8a7d138021b8a645639c56cd0046c5
The "AppData" folder and its contents are probably marked as "Hidden" and/or "Read only" by the Windows, unticking those and designating them as normal folders might help.
This is the only solution that helped me out. Please try it out and comment.

Categories

Resources