2017-04-04 66 views
3

我想從我的虛擬環境中運行manage.py runserver命令,當我做我得到這個消息當我運行./manage.py運行服務器出現錯誤導入錯誤:沒有模塊名爲芹菜

Traceback (most recent call last): 
     File "./manage.py", line 10, in <module> 
     execute_from_command_line(sys.argv) 
     File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line 
     utility.execute() 
     File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 302, in execute 
     settings.INSTALLED_APPS 
     File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 55, in __getattr__ 
     self._setup(name) 
     File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 43, in _setup 
     self._wrapped = Settings(settings_module) 
     File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 99, in __init__ 
     mod = importlib.import_module(self.SETTINGS_MODULE) 
     File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module 
     __import__(name) 
     File "/Users/ray/Desktop/sub_desk/myheroku/practice/src/gettingstarted/__init__.py", line 4, in <module> 
     from .celery import app as celery_app 
     File "/Users/ray/Desktop/sub_desk/myheroku/practice/src/gettingstarted/celery.py", line 6, in <module> 
     from celery import Celery 
    ImportError: No module named celery 

我不僅擁有芹菜,還使用virtenv以外的python 2.7。當我在進出環境時輸入哪個蟒蛇時,它們都來自相同的地點,根據搭便車者指導的蟒蛇,他們應該是分開的。這是怎麼回事?不應該在虛擬環境中使用python嗎?

然後,當我試圖點子安裝Django,芹菜我得到了以下

(practice) apples-MBP:src ray$ pip install django-celery 
    Collecting django-celery 
     Downloading django_celery-3.2.1-py2-none-any.whl (63kB) 
     100% |████████████████████████████████| 71kB 2.9MB/s 
    Requirement already satisfied: django>=1.8 in /Library/Python/2.7/site-packages (from django-celery) 
    Collecting celery<4.0,>=3.1.15 (from django-celery) 
     Downloading celery-3.1.25-py2.py3-none-any.whl (526kB) 
     100% |████████████████████████████████| 532kB 1.9MB/s 
    Collecting billiard<3.4,>=3.3.0.23 (from celery<4.0,>=3.1.15->django-celery) 
     Using cached billiard-3.3.0.23-cp27-none-macosx_10_6_intel.whl 
    Requirement already satisfied: pytz>dev in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from celery<4.0,>=3.1.15->django-celery) 
    Collecting kombu<3.1,>=3.0.37 (from celery<4.0,>=3.1.15->django-celery) 
     Using cached kombu-3.0.37-py2.py3-none-any.whl 
    Collecting anyjson>=0.3.3 (from kombu<3.1,>=3.0.37->celery<4.0,>=3.1.15->django-celery) 
     Using cached anyjson-0.3.3.tar.gz 
    Collecting amqp<2.0,>=1.4.9 (from kombu<3.1,>=3.0.37->celery<4.0,>=3.1.15->django-celery) 
     Using cached amqp-1.4.9-py2.py3-none-any.whl 
    Installing collected packages: billiard, anyjson, amqp, kombu, celery, django-celery 
    Exception: 
    Traceback (most recent call last): 
     File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 215, in main 
     status = self.run(options, args) 
     File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 342, in run 
     prefix=options.prefix_path, 
     File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 784, in install 
     **kwargs 
     File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 851, in install 
     self.move_wheel_files(self.source_dir, root=root, prefix=prefix) 
     File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files 
     isolated=self.isolated, 
     File "/Library/Python/2.7/site-packages/pip/wheel.py", line 345, in move_wheel_files 
     clobber(source, lib_dir, True) 
     File "/Library/Python/2.7/site-packages/pip/wheel.py", line 323, in clobber 
     shutil.copyfile(srcfile, destfile) 
     File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 83, in copyfile 
     with open(dst, 'wb') as fdst: 
    IOError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/_billiard.so' 
+1

您需要在'celery.py'旁邊命名_your_源文件,否則Python不知道導入全局'celery'包。 – thebjorn

+0

好吧,爲了確保事情正確設置,我會這樣做。從主pyong刪除芹菜。激活virtualenv,現在安裝芹菜,保持virtualenv激活,然後使用它。 – nomad

回答

1

首先第一件事情,虛擬環境install Celery

pip install -U Celery 

如果你得到IOError: [Errno 13] Permission denied:上你的例子如圖所示(這意味着你有this problem,你可以/應該遵循的sholve它提供的鏈接),然後使用:

sudo pip install -U Celery 

之後做到這一點:

python manage.py runserver 

看看是否可以解決您的問題。

注:

可以在PyCharm項目解釋設置爲虛擬環境

  1. 轉到文件>設置>項目:> 項目解釋。
  2. 上的齒輪圖標項目解釋單擊並選擇「添加本地」
  3. 查找~/.virtualenvs/<venv_name>/bin/python
  4. 應用,然後確定

祝你好運:)

0

在你的virtualenv安裝芹菜:

pip install django-celery 

,而在你的virtualenv啓動Django應用程序:

python manage.py runserver 
+0

感謝Dawid的迴應。我嘗試了你的方法,並在上面編輯了我的問題,所以你可以看到我的結果 –

0

一個很好的檢查是輸入pip freeze無論你在哪裏運行這個。它將打印出所有已安裝的軟件包。

+0

感謝Jeremy的迴應。當我運行pip凍結時,我注意到我的結果與我的requirements.txt應該是相同的。 –

+0

那麼'pip freeze> requirements.txt'應該改變這一點。它會在'pip freeze'中寫入requirements.txt文件。如果你想以另一種方式 - 在requirements.txt中安裝所有東西 - 輸入'pip install -r requirements.txt' –

-2

請嘗試刪除「/資源庫/Python/2.7/site-packages/_billiard'並重新安裝。

0

運行cmd作爲管理員,它一直在爲我工作。

相關問題