0

I built a python module, and tried to submit it to pypi with twine. But I get a confusing error ImportError: No module named pathlib. pathlib is a standard lib in python as os.path that does not report error.

Following is the code

import pathlib

from setuptools import setup


def read(fname):
    """
    define read method to read the long description.
    It will be shown in PyPI"""
    return pathlib.Path(fname).read_text()
William Song
  • 577
  • 6
  • 17
  • 1
    `pathlib` was only added to Python in version 3.4. What version of Python are you using to run this code? – jwodder Oct 25 '18 at 03:33
  • python3.6, it can be imported in ipython. However, I found that setup.py uses python2.7. I have fix it by changing `python setup.py sdist` to `python3 setup.py sdist` – William Song Oct 25 '18 at 03:39
  • `setup.py` only uses Python 2.7 if you tell it to use 2.7. Let me guess, you're just running `python setup.py ...`? That will use whatever version `python` points to, which is Python 2 on most systems. Use `python3 setup.py` or `python3.X setup.py` for an appropriate `X` instead. – jwodder Oct 25 '18 at 03:44
  • Thank you to remind me. but I give an alias `python` for `python3`. in terminal, `python` launches python3. – William Song Oct 25 '18 at 03:45

0 Answers0