cristianleoo / montecarlo-portfolio-management

Portfolio Management with Monte Carlo Simulation
https://montecarlo-portfolio-management.streamlit.app/
MIT License
5 stars 2 forks source link

Error when launching webpage with "streamlit run app.py" #1

Open DongDongLee87 opened 3 days ago

DongDongLee87 commented 3 days ago

Hello,

First of all, thank you for sharing this amazing code.

I want to ask how do I debug this error when launching webpage with streamlit.

image

I am working on my Macbook air M1 with VS code app.

cristianleoo commented 3 days ago

Make sure you are in the root folder. Open a new terminal in Github, type ls in the terminal and you should see something similar to:

LICENSE                 app.py                  portfolio_management    screenshots             tests
README.md               config.py               requirements.txt        setup.py                venv

Then, create a new python environment and install the dependencies

python3 -m venv venv
pip install -r requirements.txt

If you don't have pip installed you will need to run the following:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
python3 -m venv venv
pip install -r requirements.txt

Finally, run:

streamlit run app.py

Let me know if you still face an error.

DongDongLee87 commented 2 days ago

Hello,

Yes I still faced the same problem after following your step. Here is my terminal log.

`(venv) s25832581@ea:79:d6:c7:2b:2f montecarlo-portfolio-management % ls LICENSE config.py screenshots venv README.md portfolio_management setup.py app.py requirements.txt tests (venv) s25832581@ea:79:d6:c7:2b:2f montecarlo-portfolio-management % python3 -m venv venv pip install -r requirements.txt Requirement already satisfied: altair==5.4.1 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 1)) (5.4.1) Requirement already satisfied: attrs==24.2.0 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 2)) (24.2.0) Requirement already satisfied: beautifulsoup4==4.12.3 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 3)) (4.12.3) Requirement already satisfied: blinker==1.8.2 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 4)) (1.8.2) Requirement already satisfied: cachetools==5.5.0 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 5)) (5.5.0) Requirement already satisfied: certifi==2024.8.30 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 6)) (2024.8.30) Requirement already satisfied: charset-normalizer==3.3.2 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 7)) (3.3.2) Requirement already satisfied: click==8.1.7 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 8)) (8.1.7) Requirement already satisfied: contourpy==1.3.0 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 9)) (1.3.0) Requirement already satisfied: cycler==0.12.1 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 10)) (0.12.1) Requirement already satisfied: fonttools==4.53.1 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 11)) (4.53.1) Requirement already satisfied: frozendict==2.4.4 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 12)) (2.4.4) Requirement already satisfied: gitdb==4.0.11 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 13)) (4.0.11) Requirement already satisfied: GitPython==3.1.43 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 14)) (3.1.43) Requirement already satisfied: html5lib==1.1 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 15)) (1.1) Requirement already satisfied: idna==3.10 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 16)) (3.10) Requirement already satisfied: Jinja2==3.1.4 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 17)) (3.1.4) Requirement already satisfied: jsonschema==4.23.0 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 18)) (4.23.0) Requirement already satisfied: jsonschema-specifications==2023.12.1 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 19)) (2023.12.1) Requirement already satisfied: kiwisolver==1.4.7 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 20)) (1.4.7) Requirement already satisfied: lxml==5.3.0 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 21)) (5.3.0) Requirement already satisfied: markdown-it-py==3.0.0 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 22)) (3.0.0) Requirement already satisfied: MarkupSafe==2.1.5 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 23)) (2.1.5) Requirement already satisfied: matplotlib==3.9.2 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 24)) (3.9.2) Requirement already satisfied: mdurl==0.1.2 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 25)) (0.1.2) Requirement already satisfied: multitasking==0.0.11 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 26)) (0.0.11) Requirement already satisfied: narwhals==1.8.1 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 27)) (1.8.1) Requirement already satisfied: numpy==2.1.1 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 28)) (2.1.1) Requirement already satisfied: packaging==24.1 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 29)) (24.1) Requirement already satisfied: pandas==2.2.2 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 30)) (2.2.2) Requirement already satisfied: peewee==3.17.6 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 31)) (3.17.6) Requirement already satisfied: pillow==10.4.0 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 32)) (10.4.0) Requirement already satisfied: platformdirs==4.3.6 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 33)) (4.3.6) Requirement already satisfied: plotly==5.24.1 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 34)) (5.24.1) Requirement already satisfied: protobuf==5.28.2 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 35)) (5.28.2) Requirement already satisfied: pyarrow==17.0.0 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 36)) (17.0.0) Requirement already satisfied: pydeck==0.9.1 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 37)) (0.9.1) Requirement already satisfied: Pygments==2.18.0 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 38)) (2.18.0) Requirement already satisfied: pyparsing==3.1.4 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 39)) (3.1.4) Requirement already satisfied: python-dateutil==2.9.0.post0 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 40)) (2.9.0.post0) Requirement already satisfied: pytz==2024.2 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 41)) (2024.2) Requirement already satisfied: referencing==0.35.1 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 42)) (0.35.1) Requirement already satisfied: requests==2.32.3 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 43)) (2.32.3) Requirement already satisfied: rich==13.8.1 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 44)) (13.8.1) Requirement already satisfied: rpds-py==0.20.0 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 45)) (0.20.0) Requirement already satisfied: scipy==1.14.1 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 46)) (1.14.1) Requirement already satisfied: setuptools==75.1.0 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 47)) (75.1.0) Requirement already satisfied: six==1.16.0 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 48)) (1.16.0) Requirement already satisfied: smmap==5.0.1 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 49)) (5.0.1) Requirement already satisfied: soupsieve==2.6 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 50)) (2.6) Requirement already satisfied: streamlit==1.38.0 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 51)) (1.38.0) Requirement already satisfied: tenacity==8.5.0 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 52)) (8.5.0) Requirement already satisfied: toml==0.10.2 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 53)) (0.10.2) Requirement already satisfied: tornado==6.4.1 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 54)) (6.4.1) Requirement already satisfied: typing_extensions==4.12.2 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 55)) (4.12.2) Requirement already satisfied: tzdata==2024.1 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 56)) (2024.1) Requirement already satisfied: urllib3==2.2.3 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 57)) (2.2.3) Requirement already satisfied: webencodings==0.5.1 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 58)) (0.5.1) Requirement already satisfied: yfinance==0.2.43 in ./venv/lib/python3.12/site-packages (from -r requirements.txt (line 59)) (0.2.43) (venv) s25832581@ea:79:d6:c7:2b:2f montecarlo-portfolio-management % streamlit run app.py

You can now view your Streamlit app in your browser.

Local URL: http://localhost:8501 Network URL: http://192.168.1.20:8501

For better performance, install the Watchdog module:

$ xcode-select --install $ pip install watchdog

2024-11-03 12:29:43.563 Uncaught app exception Traceback (most recent call last): File "/Users/s25832581/Desktop/Portfolio_Management/montecarlo-portfolio-management/venv/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/exec_code.py", line 88, in exec_func_with_error_handling result = func() ^^^^^^ File "/Users/s25832581/Desktop/Portfolio_Management/montecarlo-portfolio-management/venv/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 590, in code_to_exec exec(code, module.dict) File "/Users/s25832581/Desktop/Portfolio_Management/montecarlo-portfolio-management/app.py", line 5, in from portfolio_management.data.data_loader import DataLoader File "/Users/s25832581/Desktop/Portfolio_Management/montecarlo-portfolio-management/portfolio_management/init.py", line 1 streamlit run app.py ^^^ SyntaxError: invalid syntax `

cristianleoo commented 2 days ago

I see that in Portfolio_Management/montecarlo-portfolio-management/portfolio_management/init.py there is the following line:

streamlit run app.py

Please remove it and run the command in the terminal instead:

streamlit run app.py