如何安装Python / Django模块?

时间:2022-04-25 11:24:12

I know absolutely nothing about Django, but I am needing to get an existing project running in OSX.

我对Django一无所知,但我需要在OSX中运行现有的项目。

From the project's directory I run python manage.py runserver and get the error: Error: No module named cms.

从项目的目录我运行python manage.py runserver并获取错误:错误:没有名为cms的模块。

Seems like the INSTALLED_APPS constant (in settings.py) defines the required modules... but how do I install the dang things?

似乎INSTALLED_APPS常量(在settings.py中)定义了所需的模块......但是如何安装dang东西呢?

Is there a standard way of installing dependencies in bulk (like Ruby's Bundler)?

是否有批量安装依赖项的标准方法(如Ruby的Bundler)?

3 个解决方案

#1


21  

you can install all dependencies in once, if there is a requirements.txt file! you just have to run the follow command:

如果有requirements.txt文件,你可以一次安装所有依赖项!你只需要运行以下命令:

pip install -r requirements.txt

otherwise you can install one by one:

否则你可以逐个安装:

pip install django-cms

Here is the PIP documentation: http://pypi.python.org/pypi/pip

以下是PIP文档:http://pypi.python.org/pypi/pip

if you are used to ruby, you can compared to ruby GEM

如果你习惯红宝石,你可以比较红宝石创业板

#2


7  

The entries in INSTALLED_APPS are package designations. Packages are a way of structuring Python’s module namespace.

INSTALLED_APPS中的条目是包名称。包是一种构造Python模块命名空间的方法。

When importing a package, Python searches through the directories on sys.path looking for the package subdirectory.

导入包时,Python会搜索sys.path上的目录,查找package子目录。

So python has some designated places to look for packages.

所以python有一些指定的地方来寻找包。

To install packages by name to the right location on your system, you could download some python source code and run the setup.py script (usually provided by libraries and applications).

要按名称将软件包安装到系统上的正确位置,您可以下载一些python源代码并运行setup.py脚本(通常由库和应用程序提供)。

$ cd /tmp
$ wget http://pypi.python.org/packages/source/p/pytz/pytz-2011n.tar.bz2
$ tar xvfj pytz-2011n.tar.bz2
$ cd pytz-2011n
$ python setup.py install

There are, however, shortcuts to this, namely easy_install and it's successor pip. With these tools, installation of a third-party package (or django app) boils down to:

然而,有一些捷径,即easy_install和它的继承点。使用这些工具,安装第三方软件包(或django应用程序)可归结为:

$ pip install pytz

Or, if you use the systems default Python installation:

或者,如果您使用系统默认的Python安装:

$ sudo pip install pytz

That's it. You can now use this library, whereever you want. To check, if it installed correctly, just try it in the console:

而已。您现在可以使用此库,无论您想要什么。要检查,如果安装正确,只需在控制台中尝试:

$ python
Python 2.7.2 (default, Aug 20 2011, 05:03:24)
...
>>> import pytz # you would get an ImportError, if pytz could not be found
>>> pytz.__version__ 
'2011n'

Now for the sake of brevity (this post is much to long already), let's assume pytz were some third party django application. You would just write:

现在为了简洁(这个帖子已经很久了),让我们假设pytz是一些第三方django应用程序。你会写:

INSTALLED_APPS = (
    'pytz',
)

And pytz would be available in your project.

并且pytz将在您的项目中可用。

Note: I you have the time, please take a look at Tools of the Modern Python Hacker: Virtualenv, Fabric and Pip blog post, which highlights some great python infrastructure tools.

注意:我有时间,请看一下现代Python黑客的工具:Virtualenv,Fabric和Pip博客文章,其中重点介绍了一些优秀的python基础设施工具。

#3


1  

Well, a little googling wouldn't hurt you ;)

好吧,有点谷歌搜索不会伤害你;)

You need a Python package manager such as easy_install and pip. Try this guide:

您需要一个Python包管理器,例如easy_install和pip。试试这本指南:

http://blog.praveengollakota.com/47430655

http://blog.praveengollakota.com/47430655

After that, you can just execute "pip install django-cms"

之后,你可以执行“pip install django-cms”

#1


21  

you can install all dependencies in once, if there is a requirements.txt file! you just have to run the follow command:

如果有requirements.txt文件,你可以一次安装所有依赖项!你只需要运行以下命令:

pip install -r requirements.txt

otherwise you can install one by one:

否则你可以逐个安装:

pip install django-cms

Here is the PIP documentation: http://pypi.python.org/pypi/pip

以下是PIP文档:http://pypi.python.org/pypi/pip

if you are used to ruby, you can compared to ruby GEM

如果你习惯红宝石,你可以比较红宝石创业板

#2


7  

The entries in INSTALLED_APPS are package designations. Packages are a way of structuring Python’s module namespace.

INSTALLED_APPS中的条目是包名称。包是一种构造Python模块命名空间的方法。

When importing a package, Python searches through the directories on sys.path looking for the package subdirectory.

导入包时,Python会搜索sys.path上的目录,查找package子目录。

So python has some designated places to look for packages.

所以python有一些指定的地方来寻找包。

To install packages by name to the right location on your system, you could download some python source code and run the setup.py script (usually provided by libraries and applications).

要按名称将软件包安装到系统上的正确位置,您可以下载一些python源代码并运行setup.py脚本(通常由库和应用程序提供)。

$ cd /tmp
$ wget http://pypi.python.org/packages/source/p/pytz/pytz-2011n.tar.bz2
$ tar xvfj pytz-2011n.tar.bz2
$ cd pytz-2011n
$ python setup.py install

There are, however, shortcuts to this, namely easy_install and it's successor pip. With these tools, installation of a third-party package (or django app) boils down to:

然而,有一些捷径,即easy_install和它的继承点。使用这些工具,安装第三方软件包(或django应用程序)可归结为:

$ pip install pytz

Or, if you use the systems default Python installation:

或者,如果您使用系统默认的Python安装:

$ sudo pip install pytz

That's it. You can now use this library, whereever you want. To check, if it installed correctly, just try it in the console:

而已。您现在可以使用此库,无论您想要什么。要检查,如果安装正确,只需在控制台中尝试:

$ python
Python 2.7.2 (default, Aug 20 2011, 05:03:24)
...
>>> import pytz # you would get an ImportError, if pytz could not be found
>>> pytz.__version__ 
'2011n'

Now for the sake of brevity (this post is much to long already), let's assume pytz were some third party django application. You would just write:

现在为了简洁(这个帖子已经很久了),让我们假设pytz是一些第三方django应用程序。你会写:

INSTALLED_APPS = (
    'pytz',
)

And pytz would be available in your project.

并且pytz将在您的项目中可用。

Note: I you have the time, please take a look at Tools of the Modern Python Hacker: Virtualenv, Fabric and Pip blog post, which highlights some great python infrastructure tools.

注意:我有时间,请看一下现代Python黑客的工具:Virtualenv,Fabric和Pip博客文章,其中重点介绍了一些优秀的python基础设施工具。

#3


1  

Well, a little googling wouldn't hurt you ;)

好吧,有点谷歌搜索不会伤害你;)

You need a Python package manager such as easy_install and pip. Try this guide:

您需要一个Python包管理器,例如easy_install和pip。试试这本指南:

http://blog.praveengollakota.com/47430655

http://blog.praveengollakota.com/47430655

After that, you can just execute "pip install django-cms"

之后,你可以执行“pip install django-cms”