# Using Pkg.build() within another build script

**URL:** <https://discourse.julialang.org/t/using-pkg-build-within-another-build-script/103121>\
**Category:** Package Management\
**Tags:** question\
**Created:** [August 23, 2023, 4:42pm UTC](https://discourse.julialang.org/t/using-pkg-build-within-another-build-script/103121 "2023-08-23T16:42:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![joegilkes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joegilkes/32/98374_2.png) [@joegilkes](https://discourse.julialang.org/u/joegilkes)\
**Post date:** [August 23, 2023, 4:42pm UTC](https://discourse.julialang.org/t/using-pkg-build-within-another-build-script/103121/1 "2023-08-23T16:42:14Z")

</div>

I’m trying to write a build script for a package that depends on PyCall.jl. In this build script, a new Conda environment gets created for PyCall to then bind to.

PyCall binds to a specific Python executable by calling `Pkg.build("PyCall")` with the `PYTHON` environment variable set to this executable. As such, my package’s `build.jl` looks something like

```julia
using Pkg
PROJECT_DIR = dirname(dirname(@ __FILE__ ))
run(`conda create --name jl_env python=3.7 --file $(joinpath(PROJECT_DIR, "requirements.txt"))`)
python_exe = chomp(readchomp(`conda run -n jl_env which python`))
ENV["PYTHON"] = python_exe
Pkg.build("PyCall")

```

When building my package, I get the following error:

```julia
ERROR: LoadError: ArgumentError: Package Pkg not found in current path.
- Run `import Pkg; Pkg.add("Pkg")` to install the Pkg package.

```

I’m taking this to mean that build scripts run in a separate environment where `Pkg` is not accessible? This makes sense, but is there any nicer way of rebuilding PyCall with the new Conda environment _within_ the build process, rather than users of my package having to separately run a post-build script?
