ImportError:无法导入名称DateRange

时间:2016-03-25 10:37:38

标签: django pip psycopg2

我正在使用PostgreSQL作为后端设置新的Django项目。我正在使用pip来安装软件包。以下是在新环境中安装的要求。

Django==1.9
argparse==1.2.1
djangorestframework==3.3.3
psycopg2==2.6.1
wsgiref==0.1.2

我不知道我犯了哪些错误。请帮我配置新项目。请给我一步一步的程序来配置新环境。

错误堆栈是

from psycopg2.extras import DateRange, DateTimeTZRange, NumericRange
ImportError: cannot import name DateRange

2 个答案:

答案 0 :(得分:0)

Sub CopyData()

'set variables for wkb and ws to copy
Dim wbSource As Workbook
Set wbSource = Workbooks("Source.xlsx")

Dim wsCopy As Worksheet
Set wsCopy = wbSource.Worksheets("Sheet1") 'change name as needed

'set variables for wkb and ws to paste
Dim wbDest As Workbook
Set wbDest = Workbooks("Destination.xlsx")

Dim wsDest As Worksheet
Set wsDest = wbDest.Worksheets("Sheet1")

'copy visible cells for specific range
With wsCopy

    Dim lRow As Long
    lRow = .Range("D" & .Rows.Count).End(xlUp).Row

    Dim rCopy As Range
    Set rCopy = Union(.Range("D7:D" & lRow), .Range("F7:F" & lRow), _
        .Range("G7:G" & lRow), .Range("I7:I" & lRow), .Range("J7:J" & lRow), _
        .Range("K7:K" & lRow), .Range("L7:L" & lRow), .Range("M7:M" & lRow), _
        .Range("O7:O" & lRow), .Range("AD7:AD" & lRow), .Range("AX7:AX" & lRow), _
        .Range("CO7:CO" & lRow), .Range("CQ7:CQ" & lRow), .Range("CR7:CR" & lRow))

End With

'paste
rCopy.SpecialCells(xlCellTypeVisible).Copy wsDest.Range("A2")

End Sub

适合我。你可以my@box:~ mkvirtualenv env (env)my@box:~ pip install -r requirements.txt (env)my@box:~ django-admin startproject proj (env)my@box:~ ./proj/manage.py shell >>> from psycopg2.extras import DateRange, DateTimeTZRange, NumericRange >>> import psycopg2吗?

答案 1 :(得分:0)

我知道这对于聚会来说为时已晚,但是显然使用psycopg2-binary对我有用。

这与Djano 2.2.9和Djongo 1.3.0一起导入psycopg2失败,并出现以下错误:

traceback (most recent call last):                                                                                                                                                                                                                                                                                           
  File "manage.py", line 21, in <module>                                                                                                                                                                                                                                                                                     
    main()                                                                                                                                                                                                                                                                                                                   
  File "manage.py", line 17, in main                                                                                                                                                                                                                                                                                         
    execute_from_command_line(sys.argv)                                                                                                                                                                                                                                                                                      
  File "/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line                                                                                                                                                                          
    utility.execute()                                                                                                                                                                                                                                                                                                        
  File "/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute                                                                                                                                                                                            
    django.setup()                                                                                                                                                                                                                                                                                                           
  File "/venv/lib/python3.6/site-packages/django/__init__.py", line 24, in setup                                                                                                                                                                                                               
    apps.populate(settings.INSTALLED_APPS)                                                                                                                                                                                                                                                                                   
  File "/venv/lib/python3.6/site-packages/django/apps/registry.py", line 114, in populate                                                                                                                                                                                                      
    app_config.import_models()                                                                                                                                                                                                                                                                                               
  File "/venv/lib/python3.6/site-packages/django/apps/config.py", line 211, in import_models                                                                                                                                                                                                   
    self.models_module = import_module(models_module_name)                                                                                                                                                                                                                                                                   
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module                                                                                                                                                                                                                                                
    return _bootstrap._gcd_import(name[level:], package, level)                                                                                                                                                                                                                                                              
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import                                                                                                                                                                                                                                                             
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load                                                                                                                                                                                                                                                          
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked                                                                                                                                                                                                                                                 
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked                                                                                                                                                                                                                                                          
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module                                                                                                                                                                                                                                                    
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed                                                                                                                                                                                                                                               
  File "/segnet-webapp/webapp/label/models.py", line 2, in <module>                                                                                                                                                                                                                                          
    from psycopg2.extras import DateRange, DateTimeTZRange, NumericRange                                                                                                                                                                                                                                                     
ModuleNotFoundError: No module named 'psycopg2' 

我将其发布在这里,因为它是搜索此特定错误时显示的少数几个地方之一。

我要做的就是:

$(venv) pip install psycopg2-binary