2011-11-10 36 views
10

Tôi tự hỏi đúng cách để cài đặt trên virtualenv với 64 bit python 2.7 pywin32 module (Hệ điều hành là Windows 7 64 bit).
Tôi đã tìm thấy trình cài đặt exe trên Sourceforge.Làm thế nào để cài đặt pywin32 trong virtualenv với python 2,7 64 bit?

Khi tôi chạy easy_installer trên dòng lệnh đầu tiên mọi thứ diễn ra tốt đẹp nhưng chẳng bao lâu tôi thấy hành vi lạ: trong khi pywin32-216.win-amd64-py2.7 cài đặt nó chạy pywin32-216-py2.7-win32.egg và nó thất bại với lỗi:

No local packages or download links found for pywin32==216 
Best match: None 

và đây là đầy đủ log của tôi:

(sandbox_virtenv) D:\test\py2exe_test>easy_install http://sourceforge.net/projects/pywin32/files/pywin32/Build216/pywin32-216.win-amd64-py2.7.exe 
Downloading http://sourceforge.net/projects/pywin32/files/pywin32/Build216/pywin32-216.win-amd64-py2.7.exe 
Processing pywin32-216.win-amd64-py2.7.exe 
pywintypes: module references __file__ 
win32evtlogutil: module references __file__ 
win32serviceutil: module references __file__ 
win32timezone: module references __file__ 
Demos.win32rcparser_demo: module references __file__ 
Demos.security.sspi.validate_password: module references __file__ 
isapi.install: module references __file__ 
isapi.samples.advanced: module references __file__ 
isapi.samples.test: module references __file__ 
isapi.test.setup: module references __file__ 
pywin.framework.scriptutils: module references __file__ 
pywin.framework.startup: module references __path__ 
pywin.scintilla.config: module references __path__ 
pywin.scintilla.control: module references __file__ 
pywin.scintilla.IDLEenvironment: module references __file__ 
scripts.regsetup: module references __file__ 
scripts.setup_d: module references __file__ 
test.testall: module references __file__ 
test.test_clipboard: module references __file__ 
test.test_win32api: module references __file__ 
test.test_win32rcparser: module references __file__ 
D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\command\bdist_egg.py:422: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal 
    symbols = dict.fromkeys(iter_symbols(code)) 
test.test_win32trace: module references __file__ 
win32com.__init__: module references __path__ 
win32com.server.register: module references __file__ 
win32com.server.register: module references __path__ 
win32com.test.GenTestScripts: module references __path__ 
win32com.test.pippo_server: module references __file__ 
win32com.test.testall: module references __file__ 
win32com.test.testAXScript: module references __path__ 
win32com.test.testDictionary: module references __file__ 
win32com.test.testPippo: module references __file__ 
win32com.test.testPyComTest: module references __file__ 
win32com.test.testServers: module references __file__ 
win32com.test.util: module references __file__ 
win32comext.adsi.__init__: module references __path__ 
win32comext.authorization.__init__: module references __path__ 
win32comext.axcontrol.__init__: module references __path__ 
win32comext.axdebug.codecontainer: module references __file__ 
win32comext.axdebug.debugger: module references __file__ 
win32comext.axdebug.__init__: module references __path__ 
win32comext.axscript.__init__: module references __path__ 
win32comext.bits.__init__: module references __path__ 
win32comext.directsound.__init__: module references __path__ 
win32comext.directsound.test.ds_test: module references __file__ 
win32comext.internet.__init__: module references __path__ 
win32comext.mapi.__init__: module references __path__ 
win32comext.shell.__init__: module references __path__ 
win32comext.shell.demos.servers.empty_volume_cache: module references __file__ 
win32comext.shell.demos.servers.folder_view: module references __file__ 
win32comext.taskscheduler.__init__: module references __path__ 
creating 'c:\users\antp~1.kyi\appdata\local\temp\easy_install-kclmxk\pywin32-216-py2.7-win32.egg' and adding 'c:\users\antp~1.kyi\appdata\local\temp\easy_install-kclmxk\pywin32-216-py2.7-win32.egg.tmp' to it 
creating d:\test\sandbox_virtenv\lib\site-packages\pywin32-216-py2.7-win32.egg 
Extracting pywin32-216-py2.7-win32.egg to d:\test\sandbox_virtenv\lib\site-packages 
Adding pywin32 216 to easy-install.pth file 
Installing pywin32_postinstall.py script to D:\test\sandbox_virtenv\Scripts 
Installing pywin32_postinstall.pyc script to D:\test\sandbox_virtenv\Scripts 
Installing pywin32_testall.py script to D:\test\sandbox_virtenv\Scripts 
Installing pywin32_testall.pyc script to D:\test\sandbox_virtenv\Scripts 

Installed d:\test\sandbox_virtenv\lib\site-packages\pywin32-216-py2.7-win32.egg 
Processing dependencies for pywin32==216 
Searching for pywin32==216 
Reading http://pypi.python.org/simple/pywin32/ 
Reading http://sf.net/projects/pywin32 
Reading https://sourceforge.net/projects/pywin32/files/pywin32/ 
Reading http://sourceforge.net/project/showfiles.php?group_id=78018 
No local packages or download links found for pywin32==216 
Best match: None 
Traceback (most recent call last): 
    File "D:\test\sandbox_virtenv\Scripts\easy_install-script.py", line 8, in <module> 
    load_entry_point('setuptools==0.6c11', 'console_scripts', 'easy_install')() 
    File "D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_install.py", line 1712, in main 
    with_ei_usage(lambda: 
    File "D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_install.py", line 1700, in with_ei_usage 
    return f() 
    File "D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_install.py", line 1716, in <lambda> 
    distclass=DistributionWithoutHelpCommands, **kw 
    File "c:\Python27\Lib\distutils\core.py", line 152, in setup 
    dist.run_commands() 
    File "c:\Python27\Lib\distutils\dist.py", line 953, in run_commands 
    self.run_command(cmd) 
    File "c:\Python27\Lib\distutils\dist.py", line 972, in run_command 
    cmd_obj.run() 
    File "D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_install.py", line 211, in run 
    self.easy_install(spec, not self.no_deps) 
    File "D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_install.py", line 422, in easy_install 
    return self.install_item(None, download, tmpdir, deps, True) 
    File "D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_install.py", line 478, in install_item 
    self.process_distribution(spec, dist, deps) 
    File "D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_install.py", line 519, in process_distribution 
    [requirement], self.local_index, self.easy_install 
    File "D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\pkg_resources.py", line 563, in resolve 
    dist = best[req.key] = env.best_match(req, self, installer) 
    File "D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\pkg_resources.py", line 799, in best_match 
    return self.obtain(req, installer) # try and download/install 
    File "D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\pkg_resources.py", line 811, in obtain 
    return installer(requirement) 
    File "D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\command\easy_install.py", line 434, in easy_install 
    self.local_index 
    File "D:\test\sandbox_virtenv\lib\site-packages\setuptools-0.6c11-py2.7.egg\setuptools\package_index.py", line 475, in fetch_distribution 
    return dist.clone(location=self.download(dist.location, tmpdir)) 
AttributeError: 'NoneType' object has no attribute 'clone' 

(sandbox_virtenv) D:\test\py2exe_test> 

Bây giờ tôi có thể nhập khẩu từ python win32api và nó khá khó hiểu

(sandbox_virtenv) D:\test\py2exe_test>python 
Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import win32api 
>>> 

Nếu bạn tìm thấy ở đây một cái gì đó không rõ ràng hỏi tôi. Cảm ơn lời khuyên của bạn.

Trả lời

9

Tôi đã tìm ra điều này, nhưng quá trình này không dễ chịu.

Có 3 vấn đề với trình cài đặt PyWin32:

  1. nó đọc python bạn cài đặt vị trí ra khỏi registry.
  2. Is giả định rằng thư mục lib của bạn là con của thư mục chứa python.exe
  3. Nó bãi 3 dlls đến% WINDIR% \ system32

Vì vậy, nếu bạn đang chạy 64 bit python 2.7 trên các cửa sổ 64 bit hoặc 32 trên 32 và môi trường ảo của bạn nằm trong c: \ scratch \ env1 \ quá trình trông giống như sau:

  1. Sao chép python.exe và pythonw.exe từ c: \ scratch \ env1 \ tập lệnh vào c: \ scratch \ env1
  2. Cập nhật giá trị "(mặc định)" trong khóa đăng ký HKLM \ SOFTWARE \ Python \ PythonCore \ 2.7 \ InstallPath \ thành "c: \ scratch \ env1 \" (đảm bảo bạn ghi Giá trị cũ.)
  3. Từ dòng lệnh, nơi bạn đã kích hoạt môi trường ảo, cài đặt PyWin32 bằng cách chạy trực tiếp installer.exe. Không sử dụng easy_install.
  4. Đặt phím installpath registry trở lại giá trị ban đầu
  5. Xóa python.exe và pythonw.exe từ c: \ cào \ env1 \
  6. di chuyển pythoncom27.dll, pywintypes27.dll và pythoncomloader27.dll từ% WINDIR % \ system32 \ đến c: \ scratch \ env1 \ (không di chuyển python27.dll hoặc bạn sẽ hối tiếc)

Hoạt động này đủ tốt để chạy django-mssql trong môi trường ảo mà không cần cài đặt pywin32 bên ngoài của môi trường ảo.

+0

ở bước 3 dòng lệnh sẽ được khởi chạy với tư cách Quản trị viên khác PyWin32 sẽ kết thúc bằng lỗi –

+0

Tôi phải đối mặt với 'import win32service như ws ImportError không tìm thấy mô-đun' khi tôi thực hiện bước 6. khi cố gắng chạy gỡ lỗi odoo trong nhật thực. tôi nghĩ rằng bước này không nên được thực hiện. –

2

Thật không may, hỗ trợ cho Python 64 bit trên Windows tương đối kém so với phiên bản 32 bit. Nó không phải là lỗi của cộng đồng Python nhưng khó khăn tương đối của việc nhận được các trình biên dịch miễn phí cho Windows 64 bit.

Nếu bạn đã cài đặt phiên bản 64 bit của Python, bạn cũng cần sử dụng các gói được tạo cho 64bit. Một số gói Python đơn giản (được viết bằng Python thuần túy và không yêu cầu thư viện bên ngoài/C) sẽ cài đặt như bình thường bằng cách sử dụng setuptools/easy_install/virtualenv. Tuy nhiên, rất nhiều gói 64bit có thể bị hỏng khi được cài đặt trong virtualenv và sẽ yêu cầu trình cài đặt.

May mắn thay, bạn có thể tìm thấy trình cài đặt được biên dịch trước 64 bit cho các gói phổ biến here. Hãy thử gói ở đó trước. Trình cài đặt sẽ nhắm mục tiêu cài đặt Python toàn cục/chính và do đó không được phân tách bởi virtualenv. Tuy nhiên, lưu ý rằng đây là không chính thức bản dựng: được cung cấp miễn phí để thuận tiện cho bạn, vì vậy, vui lòng không kiện nhà cung cấp nếu mọi thứ không thành công (hoặc mong đợi trợ giúp).

+0

Cảm ơn phản hồi. Trình cài đặt đó cũng gây ra lỗi tương tự khi tôi đưa nó cho easy_installer. Thật đáng buồn. – tony

+0

Sử dụng/khởi chạy trình cài đặt .exe (quá trình nhấp chuột), không sử dụng easy_install. Tôi không chắc chắn về xây dựng 216/xây dựng gần đây nhưng tôi đã có thể cài đặt 64 bit pywin32 trên Python 2,7 64bit trong Windows 7 như một vài tháng trước mà không có vấn đề. Hãy cho tôi biết nếu nó vẫn không hoạt động ... có lẽ chúng ta cần phải nhìn vào theo dõi lỗi nếu những người khác đang có cùng một vấn đề. – shimofuri

+0

yep, cài đặt mà không có bất kỳ công cụ bổ sung hoạt động tốt nhưng tôi đã tìm kiếm cài đặt phần mở rộng này chỉ trên môi trường ảo, tôi không muốn có nó trên cài đặt python toàn cầu của tôi. – tony

4

Với virtualenv-1.7.1.2 mới nhất, hãy thử tạo virtualenv với cờ --distribute. Tôi đã giải quyết được vấn đề chính xác giống như bạn đã có bằng cách thêm cờ.

Trên một lưu ý liên quan, trên một máy (giống hệ điều hành, Windows Server 2008 R2), tôi đã phải tạo ra các virtualenv mà không các --distribute cờ, nếu không bất cứ khi nào tôi chạy easy_install một dấu nhắc lệnh mới sẽ bật mở.

Virtualenv trên Windows giống như một tác phẩm nghệ thuật tối.

+0

Tôi nghĩ cờ '--distribute' không còn được dùng nữa và hiện không có gì. – qris

2

Đây là một câu hỏi cũ, nhưng gặp vấn đề này gần đây và tôi muốn chia sẻ những gì tôi đã làm để thực hiện công việc này. Tôi đã tìm kiếm thực hiện kerberos python trên cửa sổ, và tôi tìm thấy kerbeors_sspi có sử dụng pywin32. tất cả điều này được cài đặt bằng pip, nhưng pywin32 không thể được cài đặt bằng pip bên trong virtualenv.

Vì vậy, tôi đã vá thư viện kerberos_sspi để sử dụng pypiwin32, là một bánh xe được đóng gói bởi Glyph và el (người tạo xoắn BTW). Và bây giờ tất cả các công trình này tuyệt vời, vẫn còn nếu bạn muốn truy cập các công cụ COM bạn phải tự cài đặt pywin32 bởi vì nó cần phải được đăng ký với hệ thống.

Dưới đây là liên kết tới pypiwin32 index

Chúc mừng,

Các vấn đề liên quan