Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError no module name 'httpx' #143

Open
VianneyMI opened this issue Feb 14, 2025 · 5 comments
Open

ModuleNotFoundError no module name 'httpx' #143

VianneyMI opened this issue Feb 14, 2025 · 5 comments
Labels
bug Something isn't working

Comments

@VianneyMI
Copy link

Describe the bug
A clear and concise description of what the bug is.

Following the client tutorial, I am trying to launch the client with the weather server previously developed and I get this ModuleNotFoundError : No module name 'httpx'

Is it because I created separated virtual environments for the clients and the servers ?

Anyway, I have httpx installed in both.

How does the client process the provided server ? Do I need to launch the server manually first ?

Below is my project structure

model_context_protocol/

┣ mcp_client/
┃ ┣ .venv/
┃ ┣ .env
┃ ┣ .gitignore
┃ ┣ .python-version
┃ ┣ client.py
┃ ┣ pyproject.toml
┃ ┣ README.md
┃ ┗ uv.lock
┗ weather/
  ┣ .venv/
  ┣ .python-version
  ┣ pyproject.toml
  ┣ README.md
  ┣ uv.lock
  ┗ weather.py
@VianneyMI VianneyMI added the bug Something isn't working label Feb 14, 2025
@SHTechBoBo
Copy link

Oh, I know. There's one line in client.py: command = "python" if is_python else "node".
The logic behind it is to execute this command with anyio.open_process, if you just use python, then it will use the system's default python interpreter, not the virtual environment you created.
The true code is: command = "<YOUR_VENV_PATH>\\.venv\\Scripts\\python.exe" if is_python else "node".

@sterankin
Copy link

sterankin commented Mar 14, 2025

is this the reason my client fails with:

  File "/Users/me/src/quickstart-resources/weather-server-python/weather.py", line 3, in <module>
    from mcp.server.fastmcp import FastMCP
ModuleNotFoundError: No module named 'mcp.server.fastmcp'

even though its installed in the server?

what should YOUR_VENV_PATH be? I tried this:

command = "/Users/me/src/quickstart-resources/mcp-client-python/.venv/bin/python3.10" if is_python else "node"

I still get:


   from mcp.server.fastmcp import FastMCP
ModuleNotFoundError: No module named 'mcp.server.fastmcp'

@VianneyMI
Copy link
Author

Oh, I know. There's one line in client.py: command = "python" if is_python else "node". The logic behind it is to execute this command with anyio.open_process, if you just use python, then it will use the system's default python interpreter, not the virtual environment you created. The true code is: command = "<YOUR_VENV_PATH>\\.venv\\Scripts\\python.exe" if is_python else "node".

Thanks, this did solve my initial issue. Now I have a new one (the client hangs forever)

@VianneyMI
Copy link
Author

is this the reason my client fails with:

  File "/Users/me/src/quickstart-resources/weather-server-python/weather.py", line 3, in <module>
    from mcp.server.fastmcp import FastMCP
ModuleNotFoundError: No module named 'mcp.server.fastmcp'

even though its installed in the server?

what should YOUR_VENV_PATH be? I tried this:

command = "/Users/me/src/quickstart-resources/mcp-client-python/.venv/bin/python3.10" if is_python else "node"

I still get:


   from mcp.server.fastmcp import FastMCP
ModuleNotFoundError: No module named 'mcp.server.fastmcp'

Try to use relative paths instead

@sterankin
Copy link

Oh, I know. There's one line in client.py: command = "python" if is_python else "node". The logic behind it is to execute this command with anyio.open_process, if you just use python, then it will use the system's default python interpreter, not the virtual environment you created. The true code is: command = "<YOUR_VENV_PATH>\\.venv\\Scripts\\python.exe" if is_python else "node".

Should this path be to the client or the server venv?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants