Some time ago I wrote a tutorial here about Pweave configuration under Windows. In the tutorial you can find a batch file which does all the jobs to generate a LaTeX document and final PDF file. Here, for convenience, I am going to reproduce it and update it in some places. My initial Anaconda based installation was under Windows.
If we consider that Anaconda software distribution is already installed, the first step is to create a virtual environment (called as pweave in this example):
conda create --name pweave
conda install -n pweave python=3.6
conda install -n pweave -c conda-forge pweave
conda install -n pweave pygments
conda install -n pweave numpy
The batch file for Windows OS is (build-win.bat):
@echo off
echo "Compile script for pweave noweb documents (.pnw) under Windows OS"
echo "Requires a LaTeX installation"
echo "Requires a Python installation in form of anaconda/miniconda distribution in user directory"
echo "Requires a creation of Python virtual environment with name 'pweave'"
echo "Requires conda package installation with name 'pweave' (within the environment)"
echo "Usage example, e.g.: build-win.bat test.pnw"
set filename=%1
set filenamenoext=%~n1
REM It is recommended that you install anaconda in user directory
REM To adjust to your system setup, in the path string below, replace 'yourusername' with your own
REM and make a correction to anaconda path
set pathtoanaconda="C:\Users\yourusername\anaconda3"
echo "Compiling ...%filename%"
echo "activativating conda pweave environment and compiling by pweave ..."
CALL "%pathtoanaconda:"=%\Scripts\activate.bat" pweave
"%pathtoanaconda:"=%\envs\pweave\Scripts\pweave.exe" -f tex %filename%
echo "compiling %filenamenoext%.tex by pdflatex ... into %filenamenoext%.pdf"
REM In this script, a pdflatex is called, change it according to your TeX engine
pdflatex -synctex=1 -interaction=nonstopmode %filenamenoext%.tex
pdflatex -synctex=1 -interaction=nonstopmode %filenamenoext%.tex
CALL "%pathtoanaconda:"=%\condabin\conda.bat" deactivate
echo "Complete"
To build a document we place the batch file in an appropriate location and now we can call it as
build.bat test.pnw
from OS command line or user command in your editor.
In TeXstudio we can create an user command. To setup the user command, go to Options > Configure TeXstudio ... then select Build tab on the left. On the right pane you will see User Commands group which consists of two input fields where the leftmost is for the name of command.
Later I created a similar configuration for Linux Ubuntu and I decided to change the virtual environment to regular Python 3.9 venv (called as upve39-pweave in this example):
sudo apt install python3.9 python3.9-dev python3.9-venv
python3.9 -m venv upve39-pweave
source ./upve39-pweave/bin/activate
pip install pweave
pip install pygments
pip install numpy
deactivate
For Linux, I created a bash script (build-ubu.sh) to do the same things like in that batch file:
#!/bin/sh
echo "Compile script for pweave noweb documents (.pnw) under Linux OS"
echo "Requires a LaTeX installation"
echo "Requires a Python installation in form of anaconda/miniconda distribution in user directory"
echo "Requires a creation of Python virtual environment with name 'pweave'"
echo "Requires conda package installation with name 'pweave' (within the environment)"
echo "Usage example, e.g.: build-ubu.sh test.pnw"
fileext=${1##.} # only extension without dot
filenamenoext=${1%.} # name without extension
To adjust to your system setup, in the path string below, replace 'yourusername' with your own
pathtopython="/home/yourusername"
echo "Compiling ...$filenamenoext.$fileext"
echo "activating pweave environment and compiling by pweave ..."
$pathtopython/upve39-pweave/bin/deactivate
source $pathtopython/upve39-pweave/bin/activate
$pathtopython/upve39-pweave/bin/pweave -f tex $filenamenoext.$fileext
echo "compiling $filenamenoext.tex by *latex ... into $filenamenoext.pdf"
lualatex -synctex=1 -interaction=nonstopmode $filenamenoext.tex
lualatex -synctex=1 -interaction=nonstopmode $filenamenoext.tex
$pathtopython/upve39-pweave/bin/deactivate
echo "Complete"
So now you can call it as
build.sh test.pnw
from OS command line or user command in your editor.
Example of Pweave file opening and compiling in the TeXstudio is presented below:

knitr(and not the old Sweave), you can also execute python code just adding the optionengine=pythonto the<<>>=line. – Fran Jun 14 '22 at 10:08engine=python.. Thanks again :D – Venkat Trivikram Jun 14 '22 at 11:53