setup.py: renaming src package to project name

后端 未结 4 869
青春惊慌失措
青春惊慌失措 2020-12-24 05:39

Let\'s say you have a project called proj and in this project you have the following structure:

proj/
  dists/
  doc/
  src/
    __init__.py
            


        
4条回答
  •  囚心锁ツ
    2020-12-24 06:12

    You can try adding the src folder to the PYTHONPATH before you call the setup function:

    import sys, os
    src_path = os.path.join(os.path.realpath(os.path.dirname(__file__)), 'src')
    sys.path.append(src_path)
    

    And also, just to be on the safe side, you then change the working directory:

    os.chdir(src_path)
    

    After that, it should all be OK.

    Some other tools for packaging your app support that from within. I thought it was setuptools, turns out it's PyInstaller. But basically, that's what should be done, just enough for your packages to be imported directly.

    Turns out distutils has the package_dir directive. That is what you should use, but it might work by only adding your package to the PYTHONPATH.

提交回复
热议问题