My app.py is calling another xyz.py but unable to call and create file

If you’re creating a debugging post, please include the following info:

  1. Are you running your app locally or is it deployed? Yes
  2. If your app is deployed:
    a. Is it deployed on Community Cloud or another hosting platform?
    Community
    b. Share the link to the public deployed app.
    https://learnsuperesy.streamlit.app/
  3. Share the link to your app’s public GitHub repository (including a requirements file).
  4. Share the full text of the error message (not a screenshot).
    IN my main streamlitapp.py i am calling another python file and that file is create some text like token. I want to access that file. so in streamlit where it goes.Unable to create a file using python file
  5. Share the Streamlit and Python versions. 3.11
    3.11 is in m local it is working on both side.

if st.form_submit_button(“Submit”):
# Run the Python script with arguments
command = [
“python”, “TOTPFyers.py”,
“–fy_id”, fy_id,
“–app_id_type”, app_id,
“–totp_key”, totp_key,
“–pin”, pin,
“–app_id”, app_id,
“–secret_id”, secret_id,
“–redirect_uri”, redirect_uri
]
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
st.write(“Output:”)

                if stdout:
                    st.write("Standard Output:")
                    st.code(stdout.decode("utf-8"))
                if stderr:
                    st.write("Error Output:")
                    st.code(stderr.decode("utf-8"))

Here’s some code I recently wrote that may help. I’m pasting in a big chunk because it’s not yet in github. The code below can launch a hidden bash script, or bash script in a new terminal, or an operating system command. If you’re trying to spawn python you probably need a command like python3 my_app.py, but be sure you have the current CWD (current working directory) correct.

    def bash(self, parent, title: str, file_name: str, args: str, background: bool):
        """Run a bash script."""
        run_click = False
        folder = os.path.dirname(file_name)

        # clicked = col.button(title, None, help_str)
        c1, c2, c3 = parent.columns([10, 2, 2])
        run_click = c1.button(title, key=f"{title}-run")

        # Path to your bash script
        if run_click:
            if background:
                subprocess.Popen(
                    cwd=folder,
                    args=f"{file_name} {args}",
                    shell=True,
                )
            else:
                subprocess.Popen(
                    cwd=folder,
                    args=f'gnome-terminal -- bash -c "{file_name} {args}; exec bash"',
                    shell=True,
                )

        edit_click = c2.button("✏️", key=f"{title}-edit", help="Edit: " + file_name)
        if edit_click:
            subprocess.run([self.config_editor, file_name], check=False)

        folder_open_click = c3.button(
            "📁", key=f"{title}-open_folder", help="Open Folder: " + folder
        )
        if folder_open_click:
            subprocess.run([self.config_editor, folder], check=False)

    def cmd(self, parent, title: str, cmd_name: str, args: str):
        """Run an OS command."""
        clicked = parent.button(title)
        if clicked:
            subprocess.run([cmd_name, args], check=False)

Thanks so much… let me try that one

it worked but now it is giving pyotp not found as module.
I have installed that one already in requirment.txt

20:39:58] 🐙 Cloning into '/mount/src/siyaramapp'...
Warning: Permanently added the ED25519 host key for IP address '140.82.116.4' to the list of known hosts.
[20:39:58] 🐙 Cloned repository!
[20:39:58] 🐙 Pulling code changes from Github...
[20:39:59] 📦 Processing dependencies...

──────────────────────────────────────── uv ───────────────────────────────────────────

Using uv pip install.
Resolved 104 packages in 3.17s
Downloaded 102 packages in 8.76s
Installed 104 packages in 435ms
 + aiohttp==3.9.3
 + aiosignal==1.3.1
 + apiconnect==2.0.7
 + asyncio==3.4.3
 + attrs==23.2.0
 + automat==22.10.0
 + aws-lambda-powertools==1.25.5
 + aws-xray-sdk==2.13.1
 + backtest==0.7.8
 + backtesting==0.3.3
 + beautifulsoup4==4.12.3
 + bidict==0.23.1
 + blinker==1.8.2
 + bokeh==3.4.1
 + boto3==1.34.114
 + botocore==1.34.114
 + breeze-connect==1.0.55
 + certifi==2024.2.2
 + charset-normalizer==3.3.2
 + click==8.1.7
 + constantly==23.10.4
 + contourpy==1.2.1
 + cycler==0.12.1
 + fastjsonschema==2.19.1
 + [2024-05-28 20:40:12.733687] flask==3.0.3
 + fonttools==4.52.4
 + frozendict==2.4.4
 + frozenlist==1.4.1
 + fyers-apiv3==3.1.0
 + h11==0.14.0
 + html5lib==1.1
 + hyperlink==21.0.0
 + idna==3.7
 + incremental==22.10.0[2024-05-28 20:40:12.733964] 
 + itsdangerous==2.2.0
 + jinja2==3.1.4
 + jmespath==0.10.0
 + jsonschema==4.22.0
 + jsonschema-specifications==2023.12.1
 + jupyter-core==5.7.2
 + kiwisolver==1.4.5
 + logzero==1.7.0
 + lxml==5.2.2
 + markupsafe==2.1.5
 + matplotlib==3.9.0
 + multidict==6.0.5
 + multitasking==0.0.11
 + nbformat==5.10.4
 + numpy==1.26.4
 + outcome==1.3.0.post0
 + packaging==24.0[2024-05-28 20:40:12.734188] 
 + pandas==2.2.2
 + pandas-ta==0.3.14b0
 + peewee==3.17.5
 + pillow==10.3.0
 + platformdirs==4.2.2
 + plotly==5.22.0
 + protobuf==5.27.0
 + pya3==1.0.29
 + pyotp==2.9.0
 + pyparsing==3.1.2
 + pysocks==1.7.1
 + python-dateutil==2.9.0.post0
 + python-engineio==4.9.1
 + python-socketio==5.11.2
 + pytz==2024.1
 +[2024-05-28 20:40:12.734638]  pyyaml==6.0.1
 + referencing==0.35.1
 + rel==0.4.9.19
 + requests==2.31.0
 + rpds-py==0.18.1
 + s3transfer==0.10.1
 + selenium==4.21.0
 - setuptools==69.5.1
 + setuptools==70.0.0
 + [2024-05-28 20:40:12.734845] simple-websocket==1.0.0
 + six==1.16.0
 + smartapi-python==1.4.8
 + sniffio==1.3.1
 + sortedcontainers==2.4.0
 + soupsieve==2.5
 + ta==0.11.0
 + tenacity==8.3.0
 + tornado==6.4
 + traitlets==5.14.3
 + [2024-05-28 20:40:12.735039] trio==0.25.1
 + trio-websocket==0.11.1
 + twisted==24.3.0
 + typing-extensions==4.12.0
 + tzdata==2024.1
 + upstox-python-sdk==2.4.1
 + urllib3==2.2.1
 + uuid==1.30
 + webencodings==0.5.1
 + websocket-client==1.6.1
 + websockets==12.0
 + werkzeug==3.0.3
 + whl==0.0.4
 + wrapt==1.16.0
 + wsproto==1.2.0
 + [2024-05-28 20:40:12.735695] xlwings==0.31.3
 + xyzservices==2024.4.0
 + yarl==1.9.4
 + yfinance==0.2.40
 + zope-interface==6.4.post2
Checking if Streamlit is installed

────────────────────────────────────────────────────────────────────────────────────────

[20:40:13] 🐍 Python dependencies were installed from /mount/src/siyaramapp/requirements.txt using uv.
Check if streamlit is installed

──────────────────────────────── Installing Streamlit ──────────────────────────────────

Using uv pip install.
Resolved 41 packages in 298ms
Downloaded 16 packages in 1.91s
Installed 16 packages in 54ms
 + altair==5.3.0
 + cachetools==5.3.3
 + gitdb==4.0.11
 + gitpython==3.1.43
 + markdown-it-py==3.0.0
 + mdurl==0.1.2
 - protobuf==5.27.0
 + protobuf==4.25.3
 + pyarrow==16.1.0
 + pydeck==0.9.1
 + [2024-05-28 20:40:16.684360] pygments==2.18.0
 + rich==13.7.1
 + smmap==5.0.1
 + streamlit==1.35.0
 + toml==0.10.2
 + toolz==0.12.1
 + watchdog==4.0.1

────────────────────────────────────────────────────────────────────────────────────────

[20:40:17] 📦 Processed dependencies!



Traceback (most recent call last):
  File "/mount/src/siyaramapp/TOTPFyers.py", line 8, in <module>
    import pyotp
ModuleNotFoundError: No module named 'pyotp'
[20:41:36] 🐙 Pulling code changes from Github...
[20:41:38] 📦 Processing dependencies...
[20:41:38] 📦 Processed dependencies!
[20:41:39] 🔄 Updated app!
Traceback (most recent call last):
  File "/mount/src/siyaramapp/TOTPFyers.py", line 8, in <module>
    import pyotp
ModuleNotFoundError: No module named 'pyotp'
Traceback (most recent call last):
  File "/mount/src/siyaramapp/TOTPFyers.py", line 8, in <module>
    import pyotp
ModuleNotFoundError: No module named 'pyotp'

I’m not familiar with what deployment system you’re using but my guess is that you have more than one conda environment and pyotp is missing from one of them. If multiple shell commands are executing it’s possible it reverted back to the 'base` conda env. Lookup the commands to list out the conda modules, and print the current conda env name to troubleshoot.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.