Combining a scripting language such as Python with Anaplan can provide you and your team greater flexibility and functionality in your planning journey. If you've never used Python before, or want to check out some different ways and use cases of Python and Anaplan, look no further—this series of articles will introduce just that.

Before we jump into all that, we need to set ourselves up for success by configuring our Python environment. This is just one possible method of configuration.

假设/先决条件:

*您正在运行一个相对较新的Windows版本(本指南是用Windows 10编写的,但在最近版本的Windows中应该是相当标准的)。道歉Mac和Linux用户(尽管您正在运行Linux,希望您能管理)。

*您有能力将物品安装到计算机上,或者可以让您的IT管理团队提供帮助。

安装Python

We'll begin by installing a version of Python onto our computer. The latest version of Python can be found on their official website here:Download Python | Python.org目前是3.9.2。Python 2和3之间存在一些差异,因此,如果您是初学者,则建议安装Python 3的版本(最新),并且不需要支持任何旧版Python脚本。

根据组织的政策,你may need either an administrator to assist or have this installation packaged into a relevant software deployment package. One thing you will want to watch out for is ensuring that the installation directory is added to your system path - this is an option in the installation step itself.

与其在这些安装步骤中详细介绍,不如说明官方文档以获取进一步的安装步骤:3.在Windows上使用Python -Python 3.9.2文档。

安装代码编辑器(Visual Studio Code)

从技术上讲,您可以在这里停止并开始编写自己的.py脚本,然后通过安装在计算机上的Python实例运行它们。但是,刚开始时,拥有一个更具功能的代码编辑器很有用,这将使我们能够有效存储,管理,调试和运行我们的代码。一个这样的代码编辑器是Visual Studio代码,可以在此处免费安装:Visual Studio Code - Code Editing. Redefined.

This does not need administrator privileges to run, so should install under your local profile directly. However, VS Code needs a few extensions to really shine.

  1. 安装完成后,打开VS代码。
  2. 转到“扩展名”选项卡(左侧窗格上的俄罗斯方块图标)。
  3. 搜索“ Python”并安装此扩展程序。

Image_1.png

You're now ready to configure your Python environment!

Configuring Your Virtual Environment

在使用Python项目时,最好的做法是建立“虚拟环境”,而不是使用全球安装的环境。幸运的是,这很容易做到,并深入解释了here.

简而言之:

  1. Create a folder where you want to store your project and open this folder in VS Code.
  2. 在VS代码中打开一个新的终端窗口,然后键入以下命令:

Python -M Venv .venv

这将创建一个名为“ .venv”的新子文件夹,该档案将存储您的虚拟环境。

  1. 按“ CTRL+P”打开命令调色板,然后输入“> python:选择解释器”,然后选择此选项(请参阅ScreenShot 1)。
  2. Select the option which has the path ".\.venv\Scripts\python.exe" (see screenshot 2).
    1. 这是通往虚拟环境设置的途径,其中作为“ C:\ python ...”是我们的全球环境。
    2. Note: the version number is different because I have Python 3.7.4 installed rather than Python 3.9.0. If you installed a specific version of Python, select that one.
  3. 打开其他new terminal window (see screenshot 3), by selecting (1) option in the toolbar calledTerminal,然后单击新终端(or the shortcut Ctrl+Shift+`)
    1. The virtual environment will activate, and you should have a (.venv) prefix to the terminal lines. (see screenshot 3a)
    2. If the virtual environment is still not activated, you can manually run the启用通过运行命令脚本。\。venv \ scripts \激活在您的航站楼。

Screenshot 1:

image_2.png

Screenshot 2:

image_3.png

Screenshot 3:

新终端.png

屏幕截图3a :(请注意(.venv)in green at the start of the line)

Virtual Environment Activation.png

You're (almost) done!

要测试所有这些都已正确配置在同一终端窗口中,请输入命令:

pipinstall requests

install_requests.png

此命令完成后,请导航到Visual Studio代码中的文件资源管理器(标记为1)。向下钻入“ .venV”文件夹(这是在我们运行虚拟环境设置命令时自动创建的),然后进一步进入“ lib”,然后进入“站点包装”。在此文件夹列表中,应该有一个名为“请求”的文件夹。

2021-03-30 22_03_56-cert - Visual Studio Code.png

由于我们将使用Python进行API调用,因此我们需要安装一个名为“请求”的扩展库。pip是Python的软件包管理系统,将大量使用。下一篇文章将进一步了解pip是,为什么它有用,以及我们如何继续将其用于扩展脚本。

Coming Up

Now that we have our Python virtual environment configured, and our first package installed (requests), we can now get ready to write the first script that will help us do some workspace and model management. Stay tuned!

The content in this article has not been evaluated for all Anaplan implementations and may not be recommended for your specific situation.
在应用本文中的任何想法或步骤之前,请咨询您的内部管理员。
Comments

惊人的@kevin.cho呢感谢您推出这一点。

Glad now this is documented and something we all can reference as a resource:slightly_smiling_face:

快速问题:假设典型的Windows安装,但是对于 *不同的 *代码编辑器除了Visual Studio代码,听起来像是只需调整配置虚拟环境的部分吗?

[使用Windows 10 |Python 3.9倍|原子文本编辑器(www.atom.io)]

你好@TedemanCPA- 虚拟环境的创建应保持不变 - 在您的终端(如果您的代码编辑器具有内置的编辑器)或只是PowerShell(如果使用Windows),则可以输入同一命令以创建虚拟环境。

VS代码会自动激活环境,但可以通过运行以下命令来手动激活

。\。venv \ scripts \激活

Make sure your Powershell session is in the local directory where the ".venv" folder is stored.

此后,在您的终端中运行“ Python”将使用您的虚拟环境路径。

Done till here. Waiting to learn further.

Thanks

Arun

为延迟道歉@arunmanickam, started a new job and have been quite busy:slightly_smiling_face:

下一个article will go through setting up an Anaplan model that gives a birds-eye view of your Anaplan workspaces - workspace utilisation, model sizes, etc.

to create the sub folder .venv I had to type in

python3 -m venv .venv

Version history
Last update:
05-13-202112:39 PM
Updated by:
关于作者
  • Kevin.Cho Avatar
    经过认证的Anaplanner大师
标签(2)