Getting Started with Python4Delphi

Embarcadero Technologies
6 Oct 202009:29

Summary

TLDRこのビデオでは、Python for Delphiのセットアップ方法が説明されています。まず、SynEditをインストールし、次にPython4Delphiをバージョンコントロールから取得します。Pythonのインストールが完了すると、Pythonのビット数とアプリケーションのビット数が一致することを確認し、必要に応じて他のプラットフォーム用にPythonもインストールします。また、デモを通じてPythonを使用してGUIアプリケーションを構築する方法も紹介されています。

Takeaways

  • 💻 まず、SynEditをインストールする。GetItから利用可能で、EULAに同意してダウンロード、パッケージの構築、IDEへのインストールを行います。
  • 🔗 Python4DelphiはGetItからインストールするのではなく、Gitリポジトリからインストールします。RAD StudioのVersion ControlからGitソースを指定してインストールします。
  • 🛠️ Python4Delphiをインストール後、パッケージをビルドしてIDEに追加します。
  • 🐍 Python for Windowsをインストールする必要があります。Python 3を推奨していますが、Python 2は古く、サポートされていません。
  • 📥 Pythonを再配布する場合は、埋め込み可能なZIPファイルをダウンロードできますが、フルインストーラーを使用することもできます。
  • 💡 Pythonのビット数(32ビットまたは64ビット)は、構築するアプリケーションのビット数と一致する必要があります。
  • 🔄 異なるプラットフォーム(macOSやLinux)にデプロイする場合は、それぞれのプラットフォーム用のPythonをインストールする必要があります。
  • 🛠️ PIPはPythonのパッケージマネージャーであり、NumPyやTensorFlowなどのPythonパッケージをインストールするために使用できます。
  • 📁 環境変数のPATHにPythonと関連ライブラリのパスを追加する必要があります。これにより、IDEが正しいPythonバージョンを認識できるようになります。
  • 🔧 RAD Studioのデモプロジェクトを実行する際に、SynEditを使用してシンタックスハイライトやコードのインデント機能を利用できます。

Q & A

  • Python4Delphiとは何ですか?

    -Python4DelphiはDelphiからPythonコードを実行するためのブリッジです。Delphiの環境内でPythonの機能を利用することが可能になります。

  • SynEditをインストールするために必要な手順は何ですか?

    -まずGetItからSynEditをダウンロードし、EULAに同意してからパッケージをビルドします。その後、IDEにインストールされ、使用準備が整います。

  • Python4Delphiをインストールするためにはどの手順が必要ですか?

    -Python4DelphiのリポジトリのURLをRAD Studioから開いて、バージョンコントロールからGitソースを選択し、フォルダを作成してからパッケージをインストールします。

  • Python for Windowsをインストールする際の注意点は何ですか?

    -Python 3をインストールし、64ビットバージョンを推奨します。また、ビルドするアプリケーションのビットとPythonのビットが一致している必要があります。

  • Pythonを他のプラットフォーム(macOSやLinux)にインストールする場合のアドバイスは?

    -各プラットフォーム用のPythonをインストールする必要がありますが、多くのLinuxディストリビューションではPythonが標準でインストールされている場合もあります。

  • PIPとは何ですか?

    -PIPはPythonのパッケージマネージャーで、NumPyやTensorFlowなどのPythonパッケージをインストールするために使用されます。

  • パスの長さが長すぎるというエラーが出た場合、どのように対処しますか?

    -パスの長さ制限を無効にすることで対処できます。これは環境変数の設定やシステムプロパティの調整を通じて行うことができます。

  • デモで使用されるPythonスクリプトを実行するにはどのようにすればよいですか?

    -RAD Studioでデモプロジェクトを開いて、Pythonスクリプトを実行します。ただし、Pythonのライブラリパスが正しく設定されている必要があります。

  • SynEditが提供する機能は何ですか?

    -SynEditはシンタックスハイライトやコードのインデント機能など、テキストエディタとしての機能を提供します。

  • Pythonの複数バージョンがインストールされている場合、どのように扱えばよいですか?

    -システムにインストールされているPythonのバージョンを確認し、必要に応じてライブラリパスを調整してからビルドします。また、RAD StudioのPythonエンジン設定で特定のバージョンのDLLを指定することもできます。

  • Gitがインストールされていない場合、どのようにPython4Delphiのリポジトリを取得すればよいですか?

    -Gitがインストールされていない場合は、ZIPファイルをダウンロードするか、GitHub Desktopを使用してリポジトリをクローンできます。

Outlines

00:00

💻 Python4DelphiとSynEditのインストールガイド

このセクションでは、Python4DelphiとSynEditのインストール方法について説明しています。まず、SynEditをインストールするためにGetItを使用し、EULAに同意してダウンロードとパッケージの構築を行います。次に、Python4Delphiをインストールするために、リポジトリのURLを取得し、RAD StudioからバージョンコントロールからGitを使用してインストールします。また、Python for Windowsのインストールも必要であり、Python 3のフルインストーラーを使用するか、またはWindowsストアからインストールすることができます。Pythonのビットバージョンは、構築するアプリケーションのビットバージョンと一致する必要があります。さらに、macOSやLinuxへのデプロイが必要な場合は、それぞれのプラットフォーム用のPythonをインストールする必要があります。

05:01

🐍 Pythonを使用したGUIアプリケーションの構築

このセクションでは、Pythonを使用してGUIアプリケーションを構築する方法について説明しています。デモプロジェクトを実行し、Pythonスクリプトの実行方法を紹介しています。また、SynEditを使用してシンタックスハイライトとコードのインデント機能を有効にする方法についても説明しています。さらに、システムに複数のPythonバージョンがインストールされている場合の対処方法や、特定のビットバージョンのPythonを使用する場合の設定方法についても触れています。最後に、Gitがインストールされていない場合の対処法や、GitHub Desktopを使用する方法についても紹介されています。

Mindmap

Keywords

💡Python4Delphi

Python4Delphiは、Delphiプログラミング言語と統合されたPythonエンジンです。このエンジンを使用すると、Delphi開発者はPythonの機能を利用してアプリケーションを開発することができます。ビデオでは、Python4Delphiのインストールプロセスが説明されており、RAD StudioからGitリポジトリを通じてインストールする方法が紹介されています。

💡SynEdit

SynEditは、テキストエディタであり、プログラミング言語の構文強調表示をサポートしています。ビデオでは、SynEditのインストール方法が説明されており、GetItからインストールし、IDEに統合する方法が示されています。また、SynEditを使用することで、Pythonコードの構文強調表示とインデント機能が提供される点も触れられています。

💡EULA

EULAは「エンドユーザー使用許諾契約」の略で、ソフトウェアを使用する前にユーザーが同意する必要のある法律契約です。ビデオでは、SynEditをインストールする際にEULAに同意するプロセスが説明されています。これは、ソフトウェアのインストールプロセスにおいて一般的に必要とされるステップです。

💡Git

Gitは、分散型バージョンコントロールシステムで、コードの変更履歴を管理するためのツールです。ビデオでは、Python4DelphiをインストールするためにGitリポジトリからコードを取得する方法が説明されています。これは、オープンソースプロジェクトやチーム開発において一般的に使用される方法です。

💡RAD Studio

RAD Studioは、DelphiやC++Builderなどのプログラミング言語をサポートする統合開発環境(IDE)です。ビデオでは、RAD StudioからPython4Delphiパッケージをインストールし、ビルドする手順が説明されています。RAD Studioは、Delphi開発において中心的なツールです。

💡Python 3

Python 3は、Pythonプログラミング言語の最新のメジャーバージョンです。ビデオでは、Python 3のインストールが推奨されており、Python 2よりも優れた機能とセキュリティが説明されています。また、Pythonのビットネス(32ビットまたは64ビット)がアプリケーションのビットネスと一致する必要がある点も触れられています。

💡PIP

PIPはPythonのパッケージマネージャーであり、Pythonパッケージのインストールや管理を支援するツールです。ビデオでは、PIPを使用してNumPyやTensorFlowなどのPythonパッケージをインストールする方法が示されています。これは、Python開発において一般的に必要とされる機能です。

💡ビットネス

ビットネスは、コンピュータアーキテクチャの性能を示す指標で、32ビットや64ビットなどがあります。ビデオでは、Pythonのビットネスがアプリケーションのビットネスと一致する必要がある点が強調されています。これは、アプリケーションの互換性やパフォーマンスに影響を与える重要な要素です。

💡GetIt

GetItは、RAD Studioのパッケージマネージャーであり、DelphiやC++Builder用のパッケージをインストールする機能を提供しています。ビデオでは、SynEditがGetItからインストールされる方法が説明されていますが、Python4DelphiはまだGetItからインストールできないと触れられています。

💡エラーメッセージ

エラーメッセージは、ソフトウェアが問題を検出した際にユーザーに通知するメッセージです。ビデオでは、特定のビットネスのPython DLLが見つからないためにビルドが失敗する例が示されており、エラーメッセージが問題の診断に役立つ点が強調されています。

Highlights

Installing SynEdit from GetIt for Delphi IDE integration.

Accepting the EULA to download SynEdit packages for Windows.

Installing Python4Delphi by cloning the repository from Git.

Opening the Python4Delphi package after installation.

Building and installing the Python4Delphi package.

Installing Python for Windows to run Delphi applications.

Recommendation to use Python 3 over Python 2 for compatibility.

Installing the 64-bit version of Python for building Win64 applications.

The importance of matching Python's bittiness with the application's bittiness.

Installing Python for macOS or Linux if targeting those platforms.

Using PIP as the Python package manager to install additional packages.

Disabling the path length limit to avoid running out of path space.

Opening demo projects in RAD Studio to showcase Python for Delphi.

Error handling for missing files like 'definition.inc'.

Adding Python for Delphi libraries to the library path in RAD Studio.

Executing a Python script within a Delphi application.

Using SynEdit for syntax highlighting and behavior in Python scripts.

Building Win32 applications and the necessity of having both Python 32 and 64-bit versions.

Specifying Python engine settings in the Delphi designer.

The requirement of having Git installed for Python4Delphi installation.

Alternative methods for obtaining Python4Delphi without Git.

Transcripts

play00:00

Last week during our Python for Delphi webinar, there was some questions about how to get

play00:04

everything installed, set up.

play00:05

So I'm going to walk you through installing a Python4Delphi, Python, and SynEdit.

play00:10

So we'll start with SynEdit.

play00:13

It's available in GetIt, and eventually Python4Delphi will be in there, but we're not installing

play00:17

it from there today.

play00:19

Accept the EULA it's now going to download SynEdit and then build all the packages for

play00:25

windows.

play00:26

So it's installed in the IDE and ready to go.

play00:29

That's it we're done.

play00:31

So now I'm going to install Python4Delphi.

play00:35

To do that I have to come in here and get the URL for the repository right here.

play00:39

And then go to RAD Studio, Open from Version Control, Git, source, destination, make a

play00:49

folder to put it in.

play00:53

And now it's going to ask you what project I want to a project or project group.

play01:00

I want to install or want to open after installation.

play01:04

And so I'm going to go ahead and open the package.

play01:07

Right there, Python4Delphi.

play01:10

Now I can build this, in theory.

play01:14

Yup.

play01:15

Builds it just fine and install it.

play01:17

There's only one package right now.

play01:20

And everything's been installed.

play01:22

But in order to run anything, I need to install Python for Windows.

play01:28

Now it recommends the.

play01:30

Uh, Python 3.

play01:33

Now there was some question redistributing Python.

play01:36

So if you want to redistribute Python, um, you can just redistribute the, download the

play01:42

embeddable right here in embeddable zip file.

play01:45

And that would be the middle and that's like seven megabytes for that one.

play01:48

I think it's eight, actually.

play01:49

It's eight for that seven for that possibly.

play01:50

Um, I'm going to go ahead and do the full installer though.

play01:55

And you want Python 3, not Python 2.

play01:58

Python 2 is very old at this point and he recommended you get Python 3.

play02:05

So Python 3 finished installing or finished downloading so I'm going to run the installer.

play02:09

And I think actually you can install it from the Windows store as wall, but I'm not positive.

play02:13

And install now.

play02:16

Yes.

play02:17

And I am installing the 64-bit version.

play02:19

The, um, I could install the 32-bit version as well, but I'm going to just build Win64

play02:25

applications and use a 64 bit version.

play02:29

So the bittiness of Python has to match the bittiness of the program you are building.

play02:35

And if you want to deploy it for macOS or Linux, you would need to install the Python

play02:40

for those platforms as well.

play02:43

You could embed the embeddable version for all three platforms in there.

play02:47

Although I think most, like I was going to say, I think most Linux distros have it by

play02:52

default, but that's not true.

play02:53

They don't it's, it's optional.

play02:54

You can install it through, uh, the Linux package manager.

play02:59

So PIP is the Python package manager that you can use to install Python packages.

play03:04

If you wanted to install like num PI or TensorFlow or something like that.

play03:09

Apparently my path is getting long.

play03:12

So we'll go ahead and disable that limit.

play03:13

So I don't run out of path space, always running out of path space.

play03:18

OK, so now I'm in RAD Studio.

play03:21

So I'm going to go ahead and open the Demos and demo 31 is the one that he showed off

play03:29

during the webinar.

play03:30

And, uh, yeah I'll go ahead and save change to that.

play03:37

So this is SynEdit.

play03:39

Actually, this is a memo.

play03:40

Oh, this doesn't have SynEdit on here.

play03:43

This is just using memos.

play03:45

Actually, if we go back to here and go to demos.

play03:53

See if one of these as using?

play03:58

Nope.

play03:59

None of these SynEdit haha so SynEdit gives you the syntax highlighting, but um, none

play04:05

of these are using SynEdit.

play04:07

Interestingly.

play04:08

I thought they did while we were running this and uh, error.

play04:16

Definition.Inc.

play04:17

File not found definition.Inc.

play04:19

So I want to explore.

play04:24

I'm guessing it's in source ... definition.inc.

play04:31

Yep.

play04:32

Copy.

play04:33

Uh, I need to go tools, options.

play04:38

All of my Python for Delphi libraries, needs to be added to my path go the library path

play04:44

and it's got SynEdit.

play04:49

Added.

play04:50

Automatically, but because I didn't install it from GetIt, which it's not, in GetIt yet.

play04:56

So add, there we go.

play05:01

And now, it should build.

play05:04

Okay, so I'll run this execute.

play05:12

Yeah, there we go.

play05:17

So this is the, okay.

play05:18

This is the one that shows how to use Python to, um, build a GUI application.

play05:26

Can close, close dialogue.

play05:28

Alright.

play05:29

Yeah, that was the last one I showed.

play05:34

So let's open up a different project demos, demo1, we'll start with one.

play05:43

Okay.

play05:44

Again, this is just a memo and a memo.

play05:50

Yeah.

play05:51

Execute script for.

play05:53

So that's just a really simple one there.

play05:54

Although let's go to replace this with a Senate.

play05:58

Not that I can't rewrite that and we'll go SynEdit and we need to say.

play06:10

It is spelled right: python, we need Python Behavior, and Python Syntax highlighting.

play06:23

And then here we say, we want highlighter is Python and the behavior needs to point

play06:31

to the editor SynEdit there.

play06:33

So now we see we've got the blue on the numbers there and.

play06:37

Um, we're just going to actually, let's just do this.

play06:42

I'm going to cheat and just renamed this guy to memo1 and now cross our fingers.

play06:51

Let's see if it works.

play06:54

Okay.

play06:55

Yep.

play06:56

So not all works.

play06:57

So I've just replaced that with SynEdit.

play06:58

So SynEdit gives you the syntax highlighting also gives it the behavior.

play07:01

So it knows how to do the indentation and stuff like that.

play07:04

So if you had multiple versions of Python on your system, notice I'm building Win64.

play07:08

If I was trying to do, Win32 let's go ahead and do that, now it should fail.

play07:13

Let's see.

play07:16

Oh, um, Library path add, there.

play07:25

Save.

play07:27

Now, it should build, but it shouldn't run.

play07:32

Now it's failed because it can't find Python32.DLL.

play07:34

So, and that gives me an error message and that's because I didn't install Python 32

play07:41

I only installed Python 64.

play07:42

So I've wanted to install both.

play07:44

I would have to put both of them on there, or if I wanted to build Win32 ones.

play07:48

But then also if we go into design, oops, I accidentally closed that if we go in here

play07:56

into the designer, here is the Python engine, OK.

play08:00

And the Python engine is where you can specify things.

play08:05

So use last known version is what the default is.

play08:08

If you wanted to, you could use, uh, a specific version of Python in here, a DLL name, so

play08:15

right, here is where a specific version of the DLL and specific path, et cetera.

play08:20

So there are go quick introduction to setting up and using Python for a Delphi.

play08:25

Uh, if you don't have.

play08:28

Git installed on your computer.

play08:30

So you have to go install, Git options.

play08:38

So you have to have Git installed.

play08:39

And, uh, the path set up in here.

play08:41

If you don't have that, then from here, you can just, um, download.

play08:51

The zip file or use GitHub for Desktop to do it.

play08:56

And for some reason, they've now got a GitHub command-line interface.

play09:00

Instead of it used to have, they had to Git command line.

play09:02

I don't know when they change that.

play09:04

And now I get this weird, strange pink error box at the top.

play09:08

So yeah, you can just download the zip file.

play09:11

If you don't have Git installed on your computer.

play09:13

There you go.

play09:14

That's a quick introduction to setting up and using Python4Delphi.

Rate This

5.0 / 5 (0 votes)

Связанные теги
Python for DelphiセットアップチュートリアルSynEditRAD StudioGitPython 3パッケージ管理GUIアプリケーションデモプロジェクト
Вам нужно краткое изложение на английском?