Python 我的自定义Django应用程序代码在哪里?
我根据官方教程构建并安装了我的定制Django应用程序 安装似乎很成功Python 我的自定义Django应用程序代码在哪里?,python,django,pip,Python,Django,Pip,我根据官方教程构建并安装了我的定制Django应用程序 安装似乎很成功 $ pip install --user ../horizon2fa-0.1.tar.gz Processing /opt/stack/horizon2fa-0.1.tar.gz Requirement already satisfied (use --upgrade to upgrade): horizon2fa==0.1 from file:///opt/stack/horizon2fa-0.1.tar.gz in
$ pip install --user ../horizon2fa-0.1.tar.gz
Processing /opt/stack/horizon2fa-0.1.tar.gz
Requirement already satisfied (use --upgrade to upgrade): horizon2fa==0.1 from file:///opt/stack/horizon2fa-0.1.tar.gz in /opt/stack/.local/lib/python2.7/site-packages
Building wheels for collected packages: horizon2fa
Running setup.py bdist_wheel for horizon2fa ... done
Stored in directory: /opt/stack/.cache/pip/wheels/a6/4a/f0/4533f85d90b8f1a274a35d3865a2e0b15ff85f0570a0708679
Successfully built horizon2fa
在哪里可以找到所有自定义类和方法的源代码
我试图在我的系统中搜索,但没有找到它们。代码是否已编译
$ sudo find / -name "*horizon2fa*"
/root/.cache/pip/wheels/a0/9d/24/d8070ea2a01759ce7ebc03c34393db8a5aceccd380e60481c5/horizon2fa-0.1-cp27-none-any.whl
/opt/stack/.cache/pip/wheels/a6/4a/f0/4533f85d90b8f1a274a35d3865a2e0b15ff85f0570a0708679/horizon2fa-0.1-cp27-none-any.whl
/opt/stack/.local/lib/python2.7/site-packages/horizon2fa-0.1.dist-info
/opt/stack/horizon2fa-0.1.tar.gz
模块似乎未正确安装
python -c "import horizon2fa; print(horizon2fa.__path__)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named horizon2fa
还有我的setup.py脚本
import os
from setuptools import find_packages, setup
with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as readme:
README = readme.read()
# allow setup.py to be run from any path
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
setup(
name='horizon2fa',
version='0.1',
packages=find_packages(),
include_package_data=True,
license='BSD License', # example license
description='A Django app.',
long_description=README,
url='http://www.trex.com/',
author='trex',
author_email='trex@trex.com',
classifiers=[
'Environment :: Web Environment',
'Framework :: Django',
'Framework :: Django :: X.Y', # replace "X.Y" as appropriate
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License', # example license
'Operating System :: OS Independent',
'Programming Language :: Python',
# Replace these appropriately if you are stuck on Python 2.
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
],
)
因为您使用了--user
,所以包是为当前用户(发布pip安装--user
的用户)安装的,而不是在系统站点包
目录中。有关详细信息,请参阅文档。
因此,您应该查看文档中提到的~/.local/
,可能是:/home/%user%/.local/lib/python%version%/site packages/
另外,考虑到该软件包安装在PYTHONPATH上的某个位置,您可以尝试在shell中运行以下命令来查找它:
python -c "import %module%; print(%module%.__path__)"
i、 e
关于您的问题更新:
您应该创建一个顶级目录,例如django-horizon2fa
,并将setup.py
、MANIFEST.in
、README.RST
、LICENSE.txt
和您的horizon2fa
软件包目录放在其中。因此,与安装相关的文件位于新目录中,与模块相关的所有文件位于该目录中的目录中。当前目录设置不允许正确执行其工作
django-horizon2fa
│
├── LICENSE
├── MANIFEST.in
├── README.rst
├── setup.py
└── horizon2fa
├── __init__.py
├── admin.py
├── tests.py
├── urls.py
├── user.py
├── views.py
├── enabled
│ └── _31000_myplugin.py
├── main.py
├── migrations
│ ├── 0001_initial.py
│ └── __init__.py
├── models.py
├── panel.py
├── tests.py
├── urls.py
├── user.py
├── views.py
└── templates
├── base.html
└── horizon2fa
├── created.html
├── index.html
├── login.html
├── new.html
└── view.html
注意:在中单独使用
清单有时可能会导致在分发中包含包数据(例如模板)时出现问题。在这种情况下,考虑从<代码>清单中提供文件。在<代码>包装>数据> <代码>字典>代码> SETUP()/代码>,参见.P/>它们不是在<代码> /opt/Stask/本地/ LIB/Python 2.7/站点包< /代码>中吗?显然您使用Linux(或其他一些UNIX风格OS),因此安装路径可能是“代码>/Ur/Prime/LIb/{{您的Python版本}”。/网站包
。这至少是基于Debian的系统下的位置。我在站点包中没有看到我的源代码。ls-lh/opt/stack/.local/lib/python2.7/site-packages/horizon2fa-0.1.dist-info/total 28K-rw-rw-r--1堆栈15 Feb 25 09:38 DESCRIPTION.rst-rw-rw-r--1堆栈4 Feb 25 09:38安装程序-rw-rw-r--1堆栈905 Feb 25 09:38元数据-rw-rw-r--1堆栈967 Feb 25 09:38元数据-json-rw-rw-r--1堆栈735 Feb 25:38元数据记录-rw-rw-r--1个堆栈11 Feb 25 09:38 top_level.txt-rw-rw-r--1个堆栈93 Feb 25 09:38 Wheel我有软呢帽23美元cat/etc/fedora release fedora release 23(二十三)查看/opt/stack/.local/lib/python2.7/site packages/
,而不是horizon2fa-0.1.dist info
子目录。.dist info
目录仅包含pip元数据;实际的包将在站点包中
。我在其中只看到dist info文件夹。$ls-lh~/.local/lib/python2.7/site-packages/total 0 drwxrwxr-x 2堆栈131 Feb 25 10:04 horizon2fa-0.1.dist-info drwxrwxr-x 2堆栈45 Feb 25 09:38migrations@trex,请参阅答案更新。如果导入失败,那么包可能存在安装问题。然后,您需要将原始软件包目录结构和setup.py
添加到问题中,以便进一步研究。这可能是问题,例如,如果您使用python2 pip安装软件包,并尝试将其导入通过python3运行的脚本中-显然,python2 pip和python3 pip的软件包安装在不同的位置。Nikita,您是对的,存在安装问题。我已经更新了我的问题。@trex,更新了我的答案。请尝试我的建议,如果问题仍然存在,请告诉我们。Nikita,你是说手动创建django-horizon2fa文件夹?我手动创建了这个文件夹,并将OpenStack2faDjango项目中的所有文件复制到那里。还是不行。或者你的意思是用不同的名字开始一个新的Django项目?像django admin startproject django-horizon2fa一样。连字符是Django项目的非法字符。
python -c "import horizon2fa; print(horizon2fa.__path__)"
django-horizon2fa
│
├── LICENSE
├── MANIFEST.in
├── README.rst
├── setup.py
└── horizon2fa
├── __init__.py
├── admin.py
├── tests.py
├── urls.py
├── user.py
├── views.py
├── enabled
│ └── _31000_myplugin.py
├── main.py
├── migrations
│ ├── 0001_initial.py
│ └── __init__.py
├── models.py
├── panel.py
├── tests.py
├── urls.py
├── user.py
├── views.py
└── templates
├── base.html
└── horizon2fa
├── created.html
├── index.html
├── login.html
├── new.html
└── view.html