# PSA: Julia 1.9 Change in argument processing --

**URL:** <https://discourse.julialang.org/t/psa-julia-1-9-change-in-argument-processing/95253>\
**Category:** General Usage\
**Tags:** argument, cli\
**Created:** [February 27, 2023, 7:00am UTC](https://discourse.julialang.org/t/psa-julia-1-9-change-in-argument-processing/95253 "2023-02-27T07:00:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [February 27, 2023, 7:00am UTC](https://discourse.julialang.org/t/psa-julia-1-9-change-in-argument-processing/95253/1 "2023-02-27T07:00:13Z")

</div>

@MilesCranmer discovered a bug in pyjulia that only manifested in Julia 1.9 due to a correction in argument processing.

Suppose we have a file printargs.jl with the following content.

```julia
println(ARGS)

```

If you placed a `--` after the printargs.jl on the command line, you will get different results between Julia 1.8 and Julia 1.9:

```julia
$ julia-1.8.5/bin/julia --startup=no printargs.jl -- 1 2 3
["1", "2", "3"]

$ julia-1.9.0-beta4/bin/julia --startup=no printargs.jl -- 1 2 3
["--", "1", "2", "3"]

```

Julia 1.9 is processing the arguments correctly. Looking at the command line help, the `--` is clearly suppose to come before the programfile. If it comes after, then it should be an argument.

```julia
$ julia-1.9.0-beta4/bin/julia --help                
    julia [switches] -- [programfile] [args...]
...

```

Putting the `--` before the programfile results in consistent behavior between the versions.

```julia
$ julia-1.8.4/bin/julia --startup=no -- printargs.jl 1 2 3
["1", "2", "3"]

$ julia-1.9.0-beta2/bin/julia --startup=no -- printargs.jl 1 2 3
["1", "2", "3"]

```

> <https://github.com/JuliaLang/julia/pull/45335>
>
> Rebase of https://github.com/JuliaLang/julia/pull/37010 since that PR does not a…llow updating the author's branch.
> 
> \> This is a proposed fix for #37009. It removes manual processing of \`--\` and relies on \`getopt()\` to handle it correctly. The expected behavior:
> \> 1. If \`--\` appears before the first non-option argument, it forces the end of option processing and does not appear in \`ARGS\`.
> \> 2. If \`--\` appears after a non-option argument, it is preserved in \`ARGS\`. This \`--\` has no effect on option processing since it's already stopped on the first non-option argument.

> <https://github.com/JuliaPy/pyjulia/issues/522>
>
> I can't seem to get PyJulia working on Julia 1.9 (beta 4), although it works fin…e on 1.8.5. It seems to be some issue with the Python interpreter and libpython set by PyCall.jl. It could be interference from Conda.jl's installed copy of Python and libpython?
> 
> First, I set up a completely fresh Julia install with juliaup (note that this code will delete your \`~/.julia\` folder, only saving \`startup.jl\`):
> 
> \`\`\`bash
> mv ~/.julia/config/startup.jl ~/startup.jl && \\
> rm -rf ~/.julia && \\
> mkdir -p ~/.julia/config && \\
> mv ~/startup.jl ~/.julia/config/startup.jl && \\
> juliaup add 1.9 && \\
> juliaup default 1.9 && \\
> julia --startup-file=no -e 'using Pkg; Pkg.add(\["OhMyREPL", "Revise"\])'
> \`\`\`
> 
> Then, I run:
> 
> \`\`\`bash
> python -c 'import julia; julia.install()'
> \`\`\`
> Which succeeds. However, when I try to start Julia via PyJulia:
> 
> \`\`\`bash
> python -c 'from julia import Main'
> \`\`\`
> 
> \<details\>\<summary\> despite the exact same set of environment variables as used in the \`install\`, this fails: \</summary\>
> 
> \`\`\`bash
> Traceback (most recent call last):
> File "\<string\>", line 1, in \<module\>
> File "\<frozen importlib.\_bootstrap\>", line 1027, in \_find\_and\_load
> File "\<frozen importlib.\_bootstrap\>", line 1006, in \_find\_and\_load\_unlocked
> File "\<frozen importlib.\_bootstrap\>", line 672, in \_load\_unlocked
> File "\<frozen importlib.\_bootstrap\>", line 632, in \_load\_backward\_compatible
> File "/Users/mcranmer/venvs/main/lib/python3.10/site-packages/julia/core.py", line 247, in load\_module
> JuliaMainModule(self, fullname))
> File "/Users/mcranmer/venvs/main/lib/python3.10/site-packages/julia/core.py", line 149, in \_\_init\_\_
> self.\_julia = loader.julia
> File "/Users/mcranmer/venvs/main/lib/python3.10/site-packages/julia/core.py", line 239, in julia
> self.\_\_class\_\_.julia = julia = Julia()
> File "/Users/mcranmer/venvs/main/lib/python3.10/site-packages/julia/core.py", line 489, in \_\_init\_\_
> raise UnsupportedPythonError(jlinfo)
> julia.core.UnsupportedPythonError: It seems your Julia and PyJulia setup are not supported.
> 
> Julia executable:
> julia
> Python interpreter and libpython used by PyCall.jl:
> /Users/mcranmer/.julia/conda/3/aarch64/bin/python
> /Users/mcranmer/.julia/conda/3/aarch64/lib/libpython3.10.dylib
> Python interpreter used to import PyJulia and its libpython.
> /Users/mcranmer/venvs/main/bin/python
> /opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/Python
> 
> In Julia \>= 0.7, above two paths to \`libpython\` have to match exactly
> in order for PyJulia to work out-of-the-box. To configure PyCall.jl to use
> Python interpreter "/Users/mcranmer/venvs/main/bin/python",
> run the following code in the Python REPL:
> 
> \>\>\> import julia
> \>\>\> julia.install()
> 
> For more information, see:
> 
> https://pyjulia.readthedocs.io/en/latest/troubleshooting.html
> \`\`\`
> 
> \</details\>
> 
> In particular, the Python interpreter and libpython seem to be set incorrectly:
> 
> \`\`\`
> Python interpreter and libpython used by PyCall.jl:
> /Users/mcranmer/.julia/conda/3/aarch64/bin/python
> /Users/mcranmer/.julia/conda/3/aarch64/lib/libpython3.10.dylib
> Python interpreter used to import PyJulia and its libpython.
> /Users/mcranmer/venvs/main/bin/python
> /opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/Python
> \`\`\`
> 
> 
> I'm assuming these new \`python\` and \`libpython\` are packaged by the \`PyCall.jl\` install. But I think ideally we would want them to be set by the user from their Python/libpython, for compatibility with Python libraries, right?
> 
> \*\*I can run this entire workflow with \`juliaup add 1.8 && juliaup default 1.8\` instead, and it works fine.\*\*
> 
> cc @mkitti @ngam @stevengj @marius311 
> 
> \---
> 
> edit: I should mention I'm not using conda at all. This is a homebrew-installed version of Python running in a virtualenv.
