我是一个Mac用户,在安装python包时经常遇到挫折。
这一次,pipenv似乎工作不正常。
我成功地安装了pipenv。

$pipenv --version
pipenv, version 11.10.1

但是,当我尝试初始化pipenv shell时,出现了如下错误:
Creating a virtualenv for this project…
    Using /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 (3.6.4) to create virtualenv…
    ⠋Already using interpreter /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
    Using base prefix '/Library/Frameworks/Python.framework/Versions/3.6'
    Traceback (most recent call last):
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193, in _run_module_as_main
        "__main__", mod_spec)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/virtualenv.py", line 2349, in <module>
        main()
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/virtualenv.py", line 712, in main
        symlink=options.symlink)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/virtualenv.py", line 927, in create_environment
        site_packages=site_packages, clear=clear, symlink=symlink))
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/virtualenv.py", line 1140, in install_python
        copy_required_modules(home_dir, symlink)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/virtualenv.py", line 1070, in copy_required_modules
        dst_filename = change_prefix(filename, dst_prefix)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/virtualenv.py", line 1044, in change_prefix
        (filename, prefixes)
    AssertionError: Filename /Users/ChaewonKong/Desktop/dev/re.py does not start with any of these prefixes: ['/Library/Frameworks/Python.framework/Versions/3.6/Extras/lib/python', '/Users/ChaewonKong/Library/Python/3.6/lib/python/site-packages', '/Users/ChaewonKong/.local/lib/python/3.6/site-packages', '/Users/ChaewonKong/Library/Python/3.6/site-packages', '/Library/Frameworks/Python.framework/Versions/3.6', '/Library/Frameworks/Python.framework/Versions/3.6', '/Library/Python/3.6/site-packages']

    Virtualenv location:
    Creating a Pipfile for this project…
    Traceback (most recent call last):
      File "/Library/Frameworks/Python.framework/Versions/3.6/bin/pipenv", line 11, in <module>
        sys.exit(cli())
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 722, in __call__
        return self.main(*args, **kwargs)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 697, in main
        rv = self.invoke(ctx)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 1066, in invoke
        return _process_result(sub_ctx.command.invoke(sub_ctx))
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 895, in invoke
        return ctx.invoke(self.callback, **ctx.params)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 535, in invoke
        return callback(*args, **kwargs)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/cli.py", line 607, in shell
        three=three, python=python, fancy=fancy, shell_args=shell_args
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/core.py", line 2149, in do_shell
        ensure_project(three=three, python=python, validate=False)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/core.py", line 648, in ensure_project
        ensure_pipfile(validate=validate, skip_requirements=skip_requirements, system=system)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/core.py", line 302, in ensure_pipfile
        project.create_pipfile(python=python)
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/project.py", line 588, in create_pipfile
        required_python = self.which('python')
      File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pipenv/core.py", line 126, in which
        p = os.sep.join([location] + ['bin/{0}'.format(command)])
    TypeError: sequence item 0: expected str instance, NoneType found

最佳答案

此pipenv问题页提供了您要查找的答案:
TypeError issue

关于python - 无法在Mac中初始化Pipenv(TypeError:序列项0:预期的str实例,找不到NoneType),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50184952/

10-12 22:07