2

PTVS (Visual Studio 用の Python ツール) を使用してアプリケーションを開発したいのですが、Visual Studio 2012 用の PTVS プラグインと IronPython をダウンロードすると、完全に動作します。

ここでの私の質問は、

PTVS と ItonPython で MongoDB を使用できますか?

できる場合、どうすればよいですか?

をクリックしてインストールしようとしましたInstall Python Packageが、毎回インストールを求められ、インストールpipに失敗します。もちろん、pipがインストールされていないため、コマンドpip install pymongoは失敗します。

エラーは次のとおりです。

Installing 'pip' package manager.
Downloading setuptools from https://go.microsoft.com/fwlink/?LinkId=317603
Installing from setuptools-2.2
<string>:1: DeprecationWarning: object.__init__() takes no parameters for type KeyedRef
running install
Traceback (most recent call last):
  File "setup.py", line 202, in <module>
  File "C:\Program Files (x86)\IronPython 2.7\Lib\distutils\core.py", line 151, in setup
  File "C:\Program Files (x86)\IronPython 2.7\Lib\distutils\dist.py", line 952, in      run_commands
  File "C:\Program Files (x86)\IronPython 2.7\Lib\distutils\dist.py", line 971, in     run_command
  File "c:\users\dservicio1\appdata\local\temp\ptvs-zwgdmk-setuptools\setuptools-    2.2\setuptools\command\install.py", line 64, in run
AttributeError: 'module' object has no attribute '_getframe'Traceback (most recent call     last):
  File "C:\Program Files (x86)\Microsoft Visual Studio     11.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\2.0\pip_downloader.py",     line 61, in <module>
  File "C:\Program Files (x86)\IronPython 2.7\Lib\subprocess.py", line 512, in     check_call
subprocess.CalledProcessError: Command '['C:\\Program Files (x86)\\IronPython     2.7\\ipy.exe', 'setup.py', 'install']' returned non-zero exit status 1
'pip' failed to install. Exit code: 1
Installing 'pymongo'
Unhandled exception:
Traceback (most recent call last):
  File "C:\Program Files (x86)\IronPython 2.7\Lib\runpy.py", line 170, in run_module
  File "C:\Program Files (x86)\IronPython 2.7\Lib\runpy.py", line 103, in     _get_module_details
ImportError: No module named pip
'pymongo' failed to install. Exit code: 1

助言がありますか?

ありがとう!

4

3 に答える 3

4

残念ながら、IronPython の pip と setuptools のサポートはまだ不安定です。これらの手順に従ってpip を手動で構成することを試みることができます。その後、PTVS からパッケージをインストールできるはずですが、すべてのパッケージが古いバージョンの setuptools で動作するわけではありません。

さらに、多くのパッケージは IronPython では動作しません。基本的に、パッケージにネイティブ コード (.pyd ファイル) が含まれている場合、IronPython は CPython 拡張 API を実装していないため、パッケージは機能しません。PyMongo もその 1 つになると思います。

これに IronPython を使用しようとしている特定の理由はありますか? PTVS は通常の Python を完全にサポートしていることに注意してください。

于 2014-02-28T19:52:21.477 に答える
2

ソースからインストールを試みることができます。ソース tarball をダウンロードし、解凍して setup.py を見つけます。

ipy.exe setup.py install

または、システムの場所をきれいに保ちたい場合

ipy.exe setup.py install --user

不足している依存関係を発見する可能性が非常に高く、手動で解決する必要があります。

それもうまくいくようです:http://api.mongodb.org/python/current/installation.html#installing-without-c-extensions

于 2014-03-01T09:47:23.863 に答える
2

IronPython で pymongo を使用できない場合がありますが、IronPython から MongoDB 用の C#/.NET ドライバーを使用できます。

ドライバーの情報はこちら。このリンクで説明されているように、nuget ( PM> Install-Package mongocsharpdriver) を使用してインストールするか、dll をダウンロードするだけです。

インストールしたら、IronPython で通常の方法でアセンブリを使用できます。

    # Add reference to the Mongo C# driver
    import clr
    clr.AddReferenceToFileAndPath("MongoDB.Bson.dll")
    clr.AddReferenceToFileAndPath("MongoDB.Driver.dll")

次に、 MongoDB C# Driver APIに従って使用します。次に例を示します。

    # Get the MongoDB database
    from MongoDB.Driver import MongoClient
    client = MongoClient("mongodb://localhost")
    server = client.GetServer()
    database = server.GetDatabase("test")

    # Get a collection
    collection = database.GetCollection("users")

    # Add a document
    from MongoDB.Bson import BsonDocument
    user = BsonDocument({'first_name':'John', 'last_name':'Smith'})
    collection.Insert(user)

詳細については、MongoDB C# ドライバー APIを参照してください。

于 2014-10-30T19:20:54.693 に答える