将脚本语言(例如Python)与Anaplan结合在一起,可以为您和您的团队在计划旅程中更大的灵活性和功能。如果您以前从未使用过Python,或者想查看Python和Anaplan的一些不同方式和用例,请不要再看一下,这一系列文章将引入此信息。

在进入所有这些方面,我们需要通过配置我们的Python环境来为成功做好准备。亚搏彩票手机版免费下载这只是一种可能的配置方法。

Assumptions/Pre-Requisites:

* You're running a relatively recent version of Windows (this guide was written with Windows 10 in mind, but should be fairly standard across recent versions of Windows). Apologies Mac and Linux users (although if you're running Linux, I hope you will manage).

* You have the ability to install things onto your machine, or you can get your IT administration team to help.

Installing Python

我们将首先在计算机上安装Python版本。最新版本的Python可以在其官方网站上找到:下载python |python.organd is currently 3.9.2. There are some differences between Python 2 and 3, so recommend installing a version (recent) of Python 3 if you're a beginner and don't need to support any legacy Python scripts.

根据组织的IT政策,您可能需要管理员来协助或将此安装打包到相关的软件部署软件包中。您要注意的一件事是确保将安装目录添加到系统路径中 - 这是安装步骤本身中的一个选项。

Rather than go too detailed into these installation steps, please refer to the official documentation for further installation steps:3. Using Python on Windows — Python 3.9.2 documentation.

Installing a Code Editor (Visual Studio Code)

Technically, you could stop here and start writing your own .py scripts and running them through the Python instance installed onto your computer. However, when starting out, it's useful to have a more feature-enabled code editor, that will allow us to effectively store, manage, debug and run our code. One such code editor is Visual Studio Code, which can be installed for free here:Visual Studio代码 - 代码编辑。重新定义。

这不需要管理员特权即可运行,因此应直接在本地配置文件下安装。但是,VS代码需要一些扩展才能真正发光。

  1. 在安装完成后,打开VS代码.
  2. Go to the "extensions" tab (the Tetris-looking icon on the left-hand pane).
  3. Search for "Python" and install this extension.

image_1.png

您现在准备好配置Python环境了!

配置虚拟环境

When working with Python projects, it is best practice to set up a "virtual environment" rather than using the globally installed environment. Luckily, this is pretty easy to do and explained well in-depth这里。

In short:

  1. 创建一个文件夹,您想存储项目并在VS代码中打开此文件夹。
  2. Open a new terminal window in VS Code, and type the following command:

python -m venv .venv

This will create a new sub-folder called ".venv" which will store your virtual environment.

  1. Press "CTRL+P" to open your command palette, and type in ">Python: Select Interpreter" and select this option (see screenshot 1).
  2. 选择具有路径“。\。venv \ scripts \ python.exe”的选项(请参阅屏幕快照2)。
    1. This is the path to your virtual environment setup, where as the "C:\Python..." one is our global environment.
    2. 注意:版本号不同,因为我安装了Python 3.7.4而不是Python 3.9.0。如果您安装了Python的特定版本,请选择该版本。
  3. Openanother新的终端窗口(请参阅屏幕截图3),通过在称为工具栏中选择(1)选项终端, and then clickingNew Terminal(或快捷方式Ctrl+Shift+`)
    1. 虚拟环境将激活,并且您应该具有终端线的(.venV)前缀。(请参阅屏幕截图3a)
    2. 如果虚拟环境仍未激活,则可以手动运行Activatescript by running the command.\.venv\Scripts\activatein your terminal.

屏幕截图1:

image_2.png

屏幕截图2:

image_3.png

屏幕截图3:

新终端

Screenshot 3a: (note the(.venv)在线开始时为绿色)

虚拟环境激活

你几乎已经完成!

To test that this has all been configured properly, in the same terminal window, enter the command:

PIP安装请求

install_requests.png

Once this command completes, navigate to the file explorer in Visual Studio Code (icon labeled 1). Drill down into the ".venv" folder (this was automatically created when we ran the virtual environment setup command) and then further into "Lib" and then into "site-packages". In this list of folders, there should be a folder there called "requests".

2021-03-30 22_03_56-CERT-视觉工作室代码.png

Since we'll be making API calls using Python, we will need to install an extension library called "requests".pipis a package management system for Python and will be heavily utilized. The next article will go further into whatpipis, why it's useful, and how we'll continue to use it for extending our scripts.

接下来

现在,我们已经配置了Python虚拟环境,并且已安装了第一个软件包(请求),我们现在可以准备编写第一个脚本,以帮助我们进行一些工作区和模型管理。敬请关注!

本文中的内容尚未针对所有ANAPLAN实施进行评估,也可能不建议您针对您的具体情况进行评估。
Please consult your internal administrators prior to applying any of the ideas or steps in this article.
注释

Amazing@kevin.cho! Thanks for putting this out.

现在很高兴有记录,我们都可以将其作为资源参考:lyly_smiling_face:

Quick question: Assuming a typical Windows installation, but for a *different* code editor besides Visual Studio Code, it sounds like would just adjust the part of configuring the virtual environment?

[using Windows 10 | Python 3.9x | Atom Text Editor (www.Atom.io)]

Hi@tedemancpa- the creation of the virtual environment should remain the same - in your terminal (if your code editor has an in-built one) or just Powershell (if using Windows), you can type in the same command to create the virtual environment.

VS Code automatically activates the environment, but this can be manually activated by running the command below

.\.venv\Scripts\activate

确保您的PowerShell会话在存储“ .venV”文件夹的本地目录中。

After this, running "python" in your terminal will use your virtual environment path.

直到这里完成。等待进一步学习。

谢谢

阿伦

Apologies for the delay@ArunManickam,开始一份新工作,一直很忙:lyly_smiling_face:

下一篇文章将通过建立Anaplan模型,从而为您的Anaplan工作区提供鸟瞰图 - 工作区利用,模型尺寸等。

要创建子文件夹.venv我必须输入

python3 -m venv .venv

版本历史记录
最后更新:
‎05-13-2021下午12:39
更新者:
About the Author