I create a virtual environment with pycharts (see the answer to this question)
The virtual environment is created.
But When I tried to run the code
import streamlit as st
from pyecharts import options as opts
from pyecharts.charts import Scatter, Line
from pyecharts.faker import Faker
from pyecharts.render import make_snapshot
from snapshot_phantomjs import snapshot
def main():
st.title("Echarts Point Example with Streamlit")
if __name__ == "__main__":
main()
with streamlit run myfile.py
, the module snapshot-phantomjs could not be found. therefore I added it. Because it is not in the nix package managers, I build it with buildPythongPackage
{
description = "";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
python = pkgs.python311;
snapshot-phantomjs = with pkgs.python3Packages;
buildPythonPackage rec {
pname = "snapshot-phantomjs";
version = "0.0.3";
src = pkgs.fetchPypi {
inherit pname version;
sha256 = "3c94bc4b81147e4b44b3f745e3fbe52db4536729cdd464cbfdd2edbfb0789947";
};
propagatedBuildInputs = [ pip pep517 nose pyecharts ];
};
pyecharts = with pkgs.python3Packages;
buildPythonPackage rec {
pname = "pyecharts";
version = "2.0.6";
src = pkgs.fetchPypi {
inherit pname version;
sha256 = "4d7f8dcbee1525a6eeecab589efcdbe939feee4c46930d90b2734bff04077ecc";
};
propagatedBuildInputs = [ simplejson prettytable jinja2 ];
};
python_packages = python.withPackages(ps: with ps;[
ipython
pyecharts
snapshot-phantomjs
streamlit
]);
myDevTools = [
python_packages
];
in {
devShells.default = pkgs.mkShell {
buildInputs = myDevTools;
};
});
}
nix develop works
but when I try to run my code again (streamlit run myfile.py
), I get this error
File “/mnt/c/Users/Pierre-Olivier/Documents/doc/echart_test/withStreamlit/a.py”, line 2, in
from pyecharts import options as opts
ModuleNotFoundError: No module named ‘pyecharts’