简体   繁体   中英

How can I import a package from a local PyPI which requires authentication using PyCharm?

Introduction

I've uploaded a python package up to a local PyPI inside Artifactory. I've installed it on my system with pip install foo (I need to authenticate). I can do python -c "import foo" without any issue.

When I try to make use of this module inside PyCharm (with import foo ), PyCharm throws me unresolved reference 'foo' .

So I went into Preferences->Project:myproject->Project Interpreter->Available Packages->Manage Repositories and added the local PyPI as shown below:

添加了本地 Pypi 的管理存储库窗口

but when reloading the package list in the 'Available Packages' I get the following error dialog:

错误对话框显示“包 - 加载包列表时出错:请求失败,状态代码为 401”

401 forbidden makes since since I was never prompted for credentials, but I'm not sure how to proceed.

Question

How can I import package foo inside a PyCharm project?

PyCharm doesn't support authentication for custom package repositories, please vote for the corresponding ticket in the IDE's bug tracker https://youtrack.jetbrains.com/issue/PY-26556

Meanwhile, you should be fine installing the package from the terminal on the interpreter used as a project interpreter in PyCharm ( Settings | Project ... | Project Interpreter ).

Update to this. With version 2021.1, it looks like if you set the PIP_INDEX_URL environment variable to your Artifactory repo containing your credentials (username and API Key), you can use the "View -> Tool Window -> Python Packages" tool to install packages from your Artifactory PyPi repo. So, you would do something like:

PIP_INDEX_URL=https://<Artifactory Username>:<Artifactory API Key>@mycompany.jfrog.io/mycompany/api/pypi/pypi-org-remote/simple

Or whatever the URL is to your Artifactory pypi repo. For whatever reason, you can install from the "Python Packages" tool window, but you cannot use the "Setting -> Projects -> Python Interpreter" to install packages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM