"No module named 'sympy'" Error. Problem occurs after installation - python

I am new to Python.
I am trying to use the Sympy package.
I am running Python 3.11 in Pycharm
I am using Windows 10.
It displays:
ModuleNotFoundError: No module named 'sympy'
I ran pip install sympy, it installed it. And when I try reinstalling it, it displays:
Requirement already satisfied: sympy in c:\users\jrk\appdata\local\programs\python\python311\lib\site-packages (1.11.1)
Requirement already satisfied: mpmath>=0.19 in c:\users\jrk\appdata\local\programs\python\python311\lib\site-packages (from sympy) (1.2.1)
I tried going through this guide
https://bobbyhadz.com/blog/python-no-module-named-sympy
but it did not work.
I tried uninstalling it and reinstalling it
both with pip and mpip
it unfortunately didnt work
at the top you can see which interpreter i am using
I can see that there is a file called sympy in my downloads folder, maybe that has to be relocated, but where to?

My instructions might be a bit rusty as I don't regularly use Windows for Python but here goes:
You'll notice that the path to your Pycharm Python interpreter (c:\Users\jrk\PycharmProjects..) is different than the path reported by pip in your error messages (c:\Users\jrk\appdata..).
It's perfectly normal to have multiple versions of Python around, but you'll need to be a bit careful about which one you're invoking.
It's unclear from your description where exactly you are running the pip commands, but usually if you open built-in terminal in Pycharm, it most likely has the right virtual environment activated automatically. The command line prompt should begin with (venv) if that is the case. If you then run pip install sympy you ought to have it installed in the correct place.
If you're using a regular command prompt, you can also manually activate the virtual environment by running the activate or activate.bat file that you'll find in c:\Users\jrk\PycharmProjects\pythonProject\venv\Scripts\ folder.
Might want to also read a bit about virtual envs # https://docs.python.org/3/library/venv.html

I found the solution. I do not know why it worked. But i moved the project from the local file on my computer to the server we use in our company, and then it worked

Try Uninstalling it and reinstalling
pip uninstall sympy
pip install sympy

Related

Installing Rasterio

I tried installing Rasterio library using command- pip install rasterio and also used conda commands in anaconda cmd, both are didn't worked and it's taking too long to install so I aborted the process. Let me know in detail how to install raserio library for python?
I tried with installing GDAL and raterio whl file by using pip commands. It got installed, but when I tried to import module- it's giving me an error saying No module found. Please help to fix this.
Thanks in advance
I just had the similar problem, and tl:dr the issue for me was multiple environments, like Ameya said. Here's a longer version of Ameya's spot-on answer with steps to diagnose and fix.
Without realizing it, I had two environments going on: my jupyter notebook was running python 3.10 and my global python was running 3.9, and each was looking for site-packages in different locations (/opt/homebrew/Cellar/jupyterlab/3.4.7/libexec/lib/python3.10/site-packages vs /Users//Library/Python/3.9/lib/site-packages).
This happened because I had trouble with getting python and specifically jupyterlab running on Monterey and the only fix for me was using homebrew to manage the packages. Anything I installed with brew from the command line, went into /opt/homebrew/Cellar... etc and could be seen by my jupyter notebook. Anything I used pip install to get from within an open notebook also went onto this path that my notebook could see. But anything I used pip install from the command line to get, went to the path of the global environment's site packages. Then, my jupyter notebook couldn't see them.
You don't mention that you are using jupyter notebook but perhaps something analogous could happen between multiple environments for you.
You can check if this is the case for you by doing the following:
start python from the command line
import sys
run sys.path
start jupyter notebook, or start python from your other environment
same thing, import sys, run sys.path
Are they the same? If not, probably pip is putting your rasterio in other python env site-packages.
To fix, you can either pip install from within your preferred environment, or copy and paste the site packages corresponding to rasterio from one site-packages location to the other.

Own installed package not available in Spyder

I'm beginner in python, and I have to maintain a python code, which imports a self-made package.
I am able to install this package with pip, but somehow the Sypder(pyhton 3.9) does not accept it.
The error is: "ModuleNotFoundError: No module named 'myModule'
If I type the following command into the IPython console, then it says that the package is already installed.
pip install d:\MyFolder\myModule-0.2.0-py3-none-any.whl
Result:
Processing d:\MyFolder\myModule-0.2.0-py3-none-any.whl
myModule is already installed with the same version as the provided wheel. Use --force-reinstall to force an installation of the wheel.
Note: you may need to restart the kernel to use updated packages.
I already tried to solve this problem based this article: Spyder_modulenotfound
The packge is present in the Anaconda3 installation folder: d:\Anaconda3\Lib\site-packages\myPackage-0.2.0.dist-info\ and I added this folder into the PYTHONPATH manager tool. Already restarted the Spyder many times, still no change.
What am I missing? Please help...

Python not recognizing newly installed or some already satisfied modules

I have noticed that when I install new modules using pip install example, it installs correctly but when I try importing it in a script it says: ModuleNotFoundError: No module named 'example'. To get the modules working I have to copy the module's folder to the directory of my script. Before this started happening I had installed some modules which also work now so I'm a bit confused.
I'm guessing that there's something wrong with some PATH but I'm not really sure. How can I fix this?
Edit: I'm almost 100% sure that these problems started happening when I installed Anaconda. I have made sure Anaconda's folder is added to PATH but I still have the same issue.
With Anaconda, you would benefit from installing new packages by conda install example instead of using pip.
However, it is likely that you have installed another copy of Python that comes with Anaconda, and you should check which Python you are using by typing python -V in your command prompt or checking where it is installed (for Windows machines, check here). You might have installed the package to use with one version of Python, but your system directed you to the other one.
I have uninstalled my standalone Python distribution after installing Anaconda, so my default version of Python is the version that comes with Anaconda.

Trouble installing jupyterlab with pip

I'm fairly new to interacting with Mac OS through command line but i'm trying to make more of an effort to understand the interaction with it especially when it comes to installing programmes for programming languages. I'm trying to install jupyterlab so i ran
>>> pip install jupyterlab
and something runs so i'm assuming it has been installed somewhere.
However when then run
>>> jupyter lab or >>>jupyterlab
I get for both (command not found)
-bash: jupyterlab: command not found
Now online i've seen regarding the installation it says
"f installing using pip install --user, you must add the user-level bin directory to your PATH environment variable in order to launch jupyter lab."
Now this initially didn't mean too much to me but i've been looking into \bin files when looking at which version of python and i know
>>> which python
gives me the location of the binary for python. Naturally i tried
>>> which jupyterlab
>>> which jupyter lab
but both give me nothing.
I also get this message when i type pip install jupyterlab
Defaulting to user installation because normal site-packages is not
writeable
Requirement already satisfied: jupyterlab in
./Library/Python/2.7/lib/python/site-packages (0.33.12)
Does anyone have any ideas? Firstly do i need to add the user level bin directory to my path environment variable? If so how do i find it and how do i do that? I would really appreciate any advice broken into steps for a complete beginner. I really want to understand this so i can try to prevent issues like this in the future. I should highlight i don't have conda installed and i would like to solve this problem with pip. Thanks!
You should probably try to uninstall jupyterlab because it is installed using Python 2.7
pip uninstall jupyterlab
Then check that jupyter is non-existing by using:
which jupyterlab
And finally reinstall it using pip3 install instead of pip.
For pip to use python3.
pip3 install jupyterlab
Let me know if it worked ;)

Pip not installing at all

I am using VS code and I have been trying for two hours now. Technically I should have Pip preinstalled as I'm using 3.8.2, although when I tried downloading and installing it (from https://bootstrap.pypa.io/get-pip.py) nothing is there and nothing will come up when i type pip help/pip --version in cmd and when i do any pip install . It's not installing. Any help?
Based on my research you might one of these useful:
PIP installation is not added to the system variable – In order to be able to run Python commands from a CMD window, you will need to add the path of your PiP installation to your PATH in the system variable. If you installed Python using the installation executable, it should be added automatically.
The installation is incorrectly added in your PATH – It’s easy to mess up the PATH if you add it manually. Additional space or the missing of a semicolon before the new PATH will end up producing the error.
I'm a beginner, but I would suggest uninstalling python completely, and installing it again.

Categories