When envoking mkdocs, it crashes and gives TypeError
This happens on both my Mac (Python 3.9) and Ubuntu 20.04 (Python 3.8) systems. The mkdocs version is 1.2.3.
After having done pip install mkdocs --user mkdocs -h gives the following output (this is on my Linux machine).
I also tried to checkout mkdocs from git on my Linux box. There the master branch and the tag 1.1.2 also give the same output.
❯ mkdocs -h
Traceback (most recent call last):
File "$HOME/.local/bin/mkdocs", line 11, in <module>
load_entry_point('mkdocs', 'console_scripts', 'mkdocs')()
File "$HOME/.local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 479, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "$HOME/.local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2861, in load_entry_point
return ep.load()
File "$HOME/.local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2465, in load
return self.resolve()
File "$HOME/.local/lib/python3.8/site-packages/pkg_resources/__init__.py", line 2471, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "$HOME/.local/lib/python3.8/site-packages/mkdocs/__main__.py", line 13, in <module>
from mkdocs.commands import build, gh_deploy, new, serve
File "$HOME/.local/lib/python3.8/site-packages/mkdocs/commands/build.py", line 12, in <module>
from mkdocs.structure.nav import get_navigation
File "$HOME/.local/lib/python3.8/site-packages/mkdocs/structure/nav.py", line 4, in <module>
from mkdocs.structure.pages import Page
File "$HOME/.local/lib/python3.8/site-packages/mkdocs/structure/pages.py", line 6, in <module>
import markdown
File "$HOME/.local/lib/python3.8/site-packages/markdown/__init__.py", line 29, in <module>
from .core import Markdown, markdown, markdownFromFile # noqa: E402
File "$HOME/.local/lib/python3.8/site-packages/markdown/core.py", line 26, in <module>
from . import util
File "$HOME/.local/lib/python3.8/site-packages/markdown/util.py", line 88, in <module>
INSTALLED_EXTENSIONS = metadata.entry_points(group='markdown.extensions')
File "$HOME/.local/lib/python3.8/site-packages/importlib_metadata/__init__.py", line 1003, in entry_points
return SelectableGroups.load(eps).select(**params)
File "$HOME/.local/lib/python3.8/site-packages/importlib_metadata/__init__.py", line 453, in load
ordered = sorted(eps, key=by_group)
File "$HOME/.local/lib/python3.8/site-packages/importlib_metadata/__init__.py", line 1000, in <genexpr>
eps = itertools.chain.from_iterable(
File "$HOME/.local/lib/python3.8/site-packages/importlib_metadata/_itertools.py", line 16, in unique_everseen
k = key(element)
File "$HOME/.local/lib/python3.8/site-packages/importlib_metadata/__init__.py", line 935, in _normalized_name
return self._name_from_stem(stem) or super()._normalized_name
File "$HOME/.local/lib/python3.8/site-packages/importlib_metadata/__init__.py", line 604, in _normalized_name
return Prepared.normalize(self.name)
File "$HOME/.local/lib/python3.8/site-packages/importlib_metadata/__init__.py", line 859, in normalize
return re.sub(r"[-_.]+", "-", name).lower().replace('-', '_')
File "/usr/lib/python3.8/re.py", line 210, in sub
return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or bytes-like object
So, what am I supposed to do with this? If you think it's not necessary to provide any info how you configured MkDocs, that must mean you're assuming that this error happens for every single usage of MkDocs, which I'm quite sure it's not. What will it be, then?
I see there's no bug report template in this repo. Has adding one been discussed already? It could help users report issues with sufficient information.
@albbas the error definitely does not look like it's coming from MkDocs itself. How did you install Python? Is PYTHONPATH set and pointing to some custom directories? Could you provide your configuration as @oprypin stated, if you have any?
@albbas the error definitely does not look like it's coming from MkDocs itself. How did you install Python? Is PYTHONPATH set and pointing to some custom directories? Could you provide your configuration as @oprypin stated, if you have any?
Hi, thanks for the fast response :)
I just ran pip install mkdocs straight from the shell, hoping that it would work. Obviously, mkdocs didn't seem to like the mix of packages living in $HOME/.local/lib/python3.8/site-packages/.
Using a virtual environment solved the problems above. May I suggest that you advice on using a virtual environment in https://www.mkdocs.org/getting-started/, something á la:
$ python3 -m venv mkdocs
$ cd mkdocs
$ source bin/activate
$ pip install mkdocs
to avoid these kinds of issue reports?
The python versions on the Mac (3.9) and my Linux box (3.8) are the standard system ones, with system packages and then a smattering of packages installed by pip into $HOME/<whereever python puts packages> using pip install --user <packagename>
Yes I think such a note couldn't hurt. MkDocs potential users are not always seasoned Python developers who are aware of virtualenv practices and such.
I'd recommend installing Python CLI tools through pipx: it takes care of isolating tools from one another.
pip install --user pipx
pipx install mkdocs