Julia packages not found in vs code

huangapple go评论71阅读模式
英文:

Julia packages not found in vs code

问题

我对vscode非常不熟悉,之前一直在使用Jupyter笔记本。问题是,当我尝试在vscode中运行Julia时,它找不到之前在Jupyter中安装的任何软件包。我是否需要重新安装所有内容,或者有没有办法解决这个问题?

Julia的代码可以运行,但软件包却不能。

英文:

I'm very new to vscode and have been using previously jupyter notebooks. The problem is that when I try to run julia in vs code, it doesn't find any of the packages that have been installed with jupyter. Do I have to reinstall everything or is there some way to fix this?

The julia code works, but not the packages.

答案1

得分: 2

**1. 在Julia REPL中创建并激活项目**

在vs-code中:安装`Julia`扩展,然后按下`ctr+shift+P`,选择`Julia: Start Repl`

julia> cd("path/to/my/project/folder")
julia> pdw()
julia> ]
pkg> generate myProjectName
pkg> activate .
(myProjectName) pkg>

按退格键返回到Julia REPL提示符


**2. 在活动项目中安装包**

只需执行一次:

julia> ]
(myProjectName) pkg> add aPackageName


**3. 检查文件**

- `path/to/my/project/folder/Manifest.toml`
- `path/to/my/project/folder/Project.toml`

这些文件保存了项目的所有与包相关的信息。

**4. 组织源代码**

建议:
- 将`*.jl`源文件放入子文件夹,例如`./src`。
- 每个文件都有一个`module`:

module MyModule1
export function1, function2

include("./MyModule2.jl")

const A_CONSTANT_VALUE = "fooBar"

function function1()
    MyModule2.function3()
    ...
end

function function2()
...
end

...
end


<details>
<summary>英文:</summary>

**1. Create a project in Julia REPL and activate it** 

in vs-code: install `Julia` extension, then `ctr+shift+P`, `Julia: Start Repl`

julia> cd("path/to/my/project/folder")
julia> pdw()
julia> ]
pkg> generate myProjectName
pkg> activate .
(myProjectName) pkg>

hit backspace to go back to julia REPL promt


**2. Install a package in the active project**

You only need to do this once per package:

julia> ]
(myProjectName) pkg> add aPackageName


**3. Check files**

* `path/to/my/project/folder/Manifest.toml`
* `path/to/my/project/folder/Project.toml`

These files holds all package related infos for your project.

**4. Organize Sourcecode**

Suggestions:
- Put your `*.jl` source-files in a sub-folder, eg `./src`. 
- Have one `module` per file:

module MyModule1
export function1, function2

include(&quot;./MyModule2.jl&quot;)

const A_CONSTANT_VALUE = &quot;fooBar&quot;

function function1()
    MyModule2.function3()
    ...
end

function function2()
...
end

...
end


</details>



huangapple
  • 本文由 发表于 2023年2月18日 16:40:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75492154.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定