我有一个包
my_lib
并且想在pycharm的另一个存储库中使用它。
当我拥有我的
setup.py
文件时
from setuptools import setup, find_packages
with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
setup(
name='my_lib',
version='1.0.0',
author='Some author',
author_email='[email protected]',
description='',
long_description=long_description,
long_description_content_type="text/markdown",
url='https://github.com/my-proj/my-lib',
project_urls={
"Bug Tracker": "https://github.com/my-proj/my-lib/issues"
},
license='Apache-2.0',
packages=find_packages(),
install_requires=[
'fastapi'
],
)
我可以通过安装它
pip3.12 install -e ../my-lib
PyCharm 可以识别一切
但是,当我添加
pyproject.toml
[build-system]
requires = ["setuptools>=64", "wheel"]
build-backend = "setuptools.build_meta"
[project]
name = "my_lib"
version = "1.0.0"
description = ""
readme = "README.md"
requires-python = ">=3.10"
license = {text = "Apache-2.0"}
authors = [{name = "Some author", email = "[email protected]"}]
dependencies = [
"fastapi"
]
[project.urls]
Homepage = "https://github.com/my-proj/my-lib"
'Bug Tracker' = "https://github.com/my-proj/my-lib/issues"
其他项目无法识别类似的东西
from my_lib.a import b
不再了。
你知道如何解决吗?
我们更改了项目的依赖项以利用 pyproject.toml 而不是 setup.py,这导致了同样的问题:PyCharm 的编辑器无法识别 Cython (.pyx) 文件,但一切都正确构建。每次从 Cython 文件导入都会显示波浪形的红线。
从 PyCharm Community 2024.3 升级到 PyCharm Professional 2024.3 后,波浪状的红线消失了,Cython 文件似乎正确集成了。