<tfoot id='y2tYn'></tfoot>
    • <bdo id='y2tYn'></bdo><ul id='y2tYn'></ul>

    1. <i id='y2tYn'><tr id='y2tYn'><dt id='y2tYn'><q id='y2tYn'><span id='y2tYn'><b id='y2tYn'><form id='y2tYn'><ins id='y2tYn'></ins><ul id='y2tYn'></ul><sub id='y2tYn'></sub></form><legend id='y2tYn'></legend><bdo id='y2tYn'><pre id='y2tYn'><center id='y2tYn'></center></pre></bdo></b><th id='y2tYn'></th></span></q></dt></tr></i><div id='y2tYn'><tfoot id='y2tYn'></tfoot><dl id='y2tYn'><fieldset id='y2tYn'></fieldset></dl></div>

        <small id='y2tYn'></small><noframes id='y2tYn'>

      1. <legend id='y2tYn'><style id='y2tYn'><dir id='y2tYn'><q id='y2tYn'></q></dir></style></legend>

        从 R 或 Python 运行 .jl 文件

        Running .jl file from R or Python(从 R 或 Python 运行 .jl 文件)

            <tbody id='kEKl0'></tbody>
          • <small id='kEKl0'></small><noframes id='kEKl0'>

            <i id='kEKl0'><tr id='kEKl0'><dt id='kEKl0'><q id='kEKl0'><span id='kEKl0'><b id='kEKl0'><form id='kEKl0'><ins id='kEKl0'></ins><ul id='kEKl0'></ul><sub id='kEKl0'></sub></form><legend id='kEKl0'></legend><bdo id='kEKl0'><pre id='kEKl0'><center id='kEKl0'></center></pre></bdo></b><th id='kEKl0'></th></span></q></dt></tr></i><div id='kEKl0'><tfoot id='kEKl0'></tfoot><dl id='kEKl0'><fieldset id='kEKl0'></fieldset></dl></div>
              • <bdo id='kEKl0'></bdo><ul id='kEKl0'></ul>

                <tfoot id='kEKl0'></tfoot>
                  <legend id='kEKl0'><style id='kEKl0'><dir id='kEKl0'><q id='kEKl0'></q></dir></style></legend>
                  本文介绍了从 R 或 Python 运行 .jl 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是 Julia 的新手.我开发了几行代码来从我无法在 Python 或 R 中找到的包中获得所需的结果.现在,我试图让这个文件易于访问,并将代码包装在 Python 或 R 中.有以前有人做过吗?我尝试了几种方法,但没有发现任何有用的方法.

                  I am new to Julia. I developed a few lines of code to get the results I needed from packages I was not able to find in Python or R. Now, I am trying to get this file to be easily accessible, and wrap the code in Python or R. Has anyone done this before? I have tried a few methods and have not found anything that has helped.

                  执行此操作的最简单方法是调用 .jl 文件并运行它(然后将代码从 julia 添加到 .txt 文件中),然后在代码出现时提醒您完成了.

                  The most simple way to do this would be just a few lines of code that calls the .jl file, runs it (which the code is then added to a .txt file from julia), and then alerts you when the code is done.

                  任何帮助将不胜感激.R 是更可取的方法,此时 Python 也会受到赞赏.

                  Any help would be greatly appreciated. R is the preferable method and at this point Python would be appreciated as well.

                  推荐答案

                  请在下面找到 Python、R 和外部进程(当然是可以从任何其他进程运行的可执行命令)的说明.我建议将您的代码放在一个包中并以其中一种语言加载它,而不是将其作为外部进程执行.

                  Please find below instructions for Python, R and just an external process (which of course is an executable command that can be run from any other process). I recommend putting your code in a package and loading it in one of those languages rather than executing this as an external process.

                  1. 使用 Python Anaconda(不是内置系统 Python)并安装 Julia

                  1. Use Python Anaconda (not in-built system Python) and install Julia

                  运行 Julia 并安装 PyCall

                  Run Julia and install PyCall

                  using Pkg
                  ENV["PYTHON"]="/path/to/your/python/executable"
                  pkg"add PyCall"
                  pkg"build PyCall"
                  

                1. 将您的代码放入 Julia 包中

                2. Put your code into a Julia package

                  using Pkg
                  Pkg.generate("MyPackage")
                  

                  src 文件夹中,您将找到 MyPackage.jl,将其编辑为如下所示:

                  In the folder src you will find MyPackage.jl, edit it to look like this:

                  module MyPackage
                  function main(x,y)
                       #do very complex staff or place it in your_other_file.jl
                       2x.+y
                  end
                  include("your_other_file.jl")
                  export main, and_whatever_other_functio_you_defined
                  end
                  

                3. 安装pyjulia

                4. Install pyjulia

                  python -m pip install julia
                  

                  (在 Linux 系统上,您可能希望使用 python3 而不是 python 命令)

                  (On Linux systems you might want to use python3 instead of python command)

                  对于这一步,请注意,虽然外部 Python 可以与 Julia 一起使用.但是,为了方便起见,它可能值得考虑使用与 Julia 一起安装的 Python 作为 PyCall.在这种情况下,使用这样的命令进行安装:

                  For this step note that while an external Python can be used with Julia. However, for a convenience it might be worth to consider using a Python that got installed together with Julia as PyCall. In that case for installation use a command such this one:

                  %HOMEPATH%.juliaconda3python -m pip install julia
                  

                  或在 Linux 上

                  ~/.julia/conda/3/python -m pip install julia
                  

                  请注意,如果您定义了 JULIA_DEPOT_PATH 变量,您可以将 %HOMEPATH%.julia~/.julia/ 替换为其值.

                  Note that if you have JULIA_DEPOT_PATH variable defined you can replace %HOMEPATH%.julia or ~/.julia/ with its value.

                  运行适当的 Python 并告诉它配置 Python-Julia 集成:

                  Run the appropiate Python and tell it to configure the Python-Julia integration:

                  import julia
                  julia.install()
                  

                5. 现在你可以调用你的 Julia 代码了:

                6. Now you are ready to call your Julia code:

                  >>> from julia import Pkg
                  >>> Pkg.activate(".\MyPackage") #use the correct path
                      Activating environment at `MyPackageProject.toml`
                  >>> from julia import MyPackage
                  >>> MyPackage.main([1,2],5)
                      [7,9]
                  

                7. Gnu R

                  1. 配置您的系统 PATH 变量以指向您的 Julia 位置.因此,当您在控制台中键入 julia 时,它应该启动 Julia

                  1. Configure your system PATH variable to point to your Julia location. Hence when you type julia in the console it should start Julia

                  运行下面的脚本来安装 R-Julia 集成

                  Run the script below to install R-Julia integration

                  install.packages("JuliaCall")
                  
                  library(JuliaCall)
                  julia <- julia_setup()
                  

                  1. 按照上述 Python 说明(仅限第 3 步)并创建名为 MyPackage

                  运行代码

                  library(JuliaCall)
                  julia_eval("using Pkg;Pkg.activate("C:/temp/rrr/MyPackage")")
                  julia_library("MyPackage")
                  
                  julia_eval("MyPackage.main(3,5)")
                  

                  Bash(或任何语言)

                  1. 按照 Python 说明构建包(仅限第 3 步)

                  1. Build the package following instructions for Python (step 3 only)

                  配置系统PATH变量

                  在包目录中运行命令(注意 string(:.) 是一个 Julian 技巧,我用它来避免 bash 命令中的撇号转义):

                  Being in the package directory run the command (note string(:.) is a Julian trick that I use to avoid apostrophe escaping in bash commands):

                  julia -e "using Pkg;Pkg.activate(string(:.));Pkg.instantiate();using MyPackage;MyPackage.main(3,4)"
                  

                  这将为您的包安装所有依赖项.为了跳过安装,请从上述命令中删除 Pkg.instantiate().

                  This will install all dependencies for your package. In order to skip the installation remove Pkg.instantiate() from the above command.

                  这篇关于从 R 或 Python 运行 .jl 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Running Julia .jl file in python(在 python 中运行 Julia .jl 文件)
                  Using PIP in a Azure WebApp(在 Azure WebApp 中使用 PIP)
                  How to run python3.7 based flask web api on azure(如何在 azure 上运行基于 python3.7 的烧瓶 web api)
                  Azure Python Web App Internal Server Error(Azure Python Web 应用程序内部服务器错误)
                  Run python dlib library on azure app service(在 azure app 服务上运行 python dlib 库)
                  Django channels and azure(Django 频道和天蓝色)
                    <tbody id='1Ljai'></tbody>

                  1. <tfoot id='1Ljai'></tfoot>

                    • <i id='1Ljai'><tr id='1Ljai'><dt id='1Ljai'><q id='1Ljai'><span id='1Ljai'><b id='1Ljai'><form id='1Ljai'><ins id='1Ljai'></ins><ul id='1Ljai'></ul><sub id='1Ljai'></sub></form><legend id='1Ljai'></legend><bdo id='1Ljai'><pre id='1Ljai'><center id='1Ljai'></center></pre></bdo></b><th id='1Ljai'></th></span></q></dt></tr></i><div id='1Ljai'><tfoot id='1Ljai'></tfoot><dl id='1Ljai'><fieldset id='1Ljai'></fieldset></dl></div>

                        • <bdo id='1Ljai'></bdo><ul id='1Ljai'></ul>

                            <legend id='1Ljai'><style id='1Ljai'><dir id='1Ljai'><q id='1Ljai'></q></dir></style></legend>
                          • <small id='1Ljai'></small><noframes id='1Ljai'>