I am using different environment (Conda) for the project (python 3.10.9). When I import libraries and packages etc, it is importing from that environment's path. But when I import streamlit-extras package, even though it is installed on the same environment, It is searching from other version (python 3.7) and therefore giving ModuleNotFound Error. I looked here and other questions but couldn't solve my problem. I checked the current environment's location and streamlit-extras is there.
ModuleNotFoundError: No module named 'streamlit_extras.let_it_rain'
Traceback:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script
exec(code, module.__dict__)
File "/Users/abduraimovusmanjon/Desktop/danger/pages/1_🎢_Insights.py", line 16, in <module>
from streamlit_extras.let_it_rain import rain
As seen from the error, it is looking some other path (python 3.7) for only this package, even if the package is located on the same environment which I am working. Any other import is working without problem.
Is there easier way that whenever I import, python will stick on the current environment?
Or any other way to solve this issue?
Thanks in advance for help!
It looks like you have another installed version of streamlit-extras, which was installed outside of the pip package manager.
And that other version takes precedence over the pip one.
You can check your PATH variable: it will show you which directories are looked at to resolve your streamlit-extras and the order in which they are checked.
One of the earlier paths likely points to /Library/Frameworks/Python.framework/Versions/3.7/lib. Either remove it, or re-order paths so that your Conda environment path shows first.
Related
I am using Anaconda installed on Windows 10. Recently I started running into a DLL loading error when I tried to call numpy (and sometimes sklearn):
File
"C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\__init__.py",
line 22, in <module>
from . import multiarray File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\multiarray.py",
line 12, in <module>
from . import overrides File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\overrides.py",
line 7, in <module>
from numpy.core._multiarray_umath import ( ImportError: DLL load failed: The specified module could not be found.
For NumPy, at least, I don't run into this issue if using jupyter notebook, started from anaconda prompt. If I tried to use another interpreter (like sublime or vs code using their conda extensions) that has been configured to look for the anaconda installation of Python, I get this error.
The thing is, "\Anaconda3\lib" doesn't exist on my machine, because on Windows, the libraries are installed in "\Anaconda3\Lib". So I have no idea why python is looking for packages in a folder that doesn't exist. In jupyter notebook (opened via anaconda prompt), the directory for packages also points to the "lib" folder, even though in that environment it doesn't seem to be a problem.
I tried starting a new environment in conda, and it still has the same issue. If anyone can explain what's going on here, I would greatly appreciate it. Is this a PATH addition issue (I didn't add an anaconda path to windows, since it's recommended by the anaconda installer)?
In trying to install packages in Pycharm for the Python 3.6 interpreter, I get
Python packaging tools not found. *Install packaging tools*
And when I tried to install it gives me this error
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition
2017.3.1\helpers\packaging_tool.py", line 2, in <module>
import traceback
ModuleNotFoundError: No module named 'traceback'
I'm using Pycharm 2017.3.1 Community Edition
From pycharm,
goto settings -> project Interpreter
Click on + button on top right corner and you will get pop-up window of Available packages. Then search for packaging python package.
Then click on Install package to install the package.
I had a similar issue. In the end I had to remove an existing venv that was in the same location, delete multiple interpreters, then set up a new one.
For what it's worth..
I had a similar problem. Nothing answered here worked for me.
The problem started with Pycharm upgrade. The solution was to uninstall Pycharm, and obliterate what's in the Configuration directory (https://www.jetbrains.com/help/pycharm/directories-used-by-the-ide-to-store-settings-caches-plugins-and-logs.html#config-directory) along with alll jetbrains directories.
Reinstalled Phycharm 2022.1.1. Viola. Alas I have to reinstall all plugins I used in the old installation.
As far as I can tell, the problem - in my case at least - was the upgrade process.
The accepted answer wouldn't directly work if you have already created a Virtual environment.
That virtual environment would not be usable. So, go ahead and delete it.
Then, go and install the packaging module in the base python version, as shown in the accepted answer and then create a new virtual environment.
That new virtual environment can now be used.
Here is the error
import numpy
Exception has occurred: ModuleNotFoundError
No module named 'numpy'
File "C:\path\to\file\32.py", line 1, in <module>
import numpy
Let me know how did you install the NumPy package; using pip or something else?
If you have multiple python versions, i.e. 2.x and 3.x at the same time, please make sure your interpreter for the 32.py file is the version that you installed NumPy on.
To possibly fix your problem, you should first try installing it and see if there are any errors. You should also check the version of Python you are running on Windows 10, because when you update Python it sometimes switches names between py and python
As you can see, the version of Python has changed between py and python so you should try changing that first.
If this does not work, you should try finding the directory for NumPy and adding it to the system PATH in your script. The installer usually shows you the location by doing the following:
import sys
sys.path.append("<insert numpy location here>")
import NumPy
This should manually force it into finding the package. If none of this works, please tell us and we should be able to find a different solution.
Happy Coding!
If you're using a code editor like PyCharm, you could install it by clicking on
file then settings then the project interpreter setting and install new module! You can search for the module and install.
Make sure that the python version that you want to use is a Windows Environmental Variable. You can test this by running this line in your command line.
> python --version
If you get some other python version that is not the one that you wish to use you can set the python version you want by finding where exactly your Python folder is located and go into settings and set the path as a new variable (I can leave a tutorial for you). If that is too much of a hassle, the Python installers can set the python that you will install as an environmental variable for you. (You could uninstall and reinstall and make sure that you allow it to make it an environmental variable.
After that you should be able to import whatever external packages you want using pip
for example:
pip install numpy
I realize this is a very newbie question, but previous threads haven't been encouraging (see details below).
I've been using anaconda for most of my work via the IPython Notebook, python 2.7
However, there is a module which I could only properly download with MacPorts. Hence the current problem: when I try to use the Python command line in Terminal or use IPython notebooks, I will enter
import py-module
and I get
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named py-module
So, obviously the $PATH is wrong. All my previous modules have been saved with conda to /anaconda/bin, but using sudo port install py-module is going to save in a different file, /opt/local.
Is it possible to set the path such that MacPorts will install a module into anaconda/bin
such that I can import this module on ipython notebook via conda?
Previous threads have suggested simply choosing one or the other, i.e. removing anaconda entirely
rm -r ~/anaconda
and then just reinstalling all packages via MacPort. But I would prefer not to do this. Can't I re-direct the path such that
sudo port install py-module
installs the module into `/anaconda/bin/' ?
For previous takes, see
Getting PyGame to import in Python interpreter after MacPorts install
While you could adjust your PYTHONPATH environment variable or modify the path using sys.path.insert, you should not try to mix a Python module built for MacPorts' Python with Anaconda. This may work just fine if the module is python-only, but as soon as the module contains compiled code it is not certain that the two installations are binary-compatible. In the best case, loading the module will fail if it isn't compatible, in the worst case, it will randomly crash.
So, yes, you should decide for one Python and just use that.
So i had python 2.7.2 on my server and i needed to update it to python 2.7.3. So i've tried to remove the 2.7.2 version and then install the new one using the sources. I wasn't able to remove the 2.7.2 version cause the system uses it to run crucial services on server, so i installed the 2.7.3 version in hope that after that i would be able to remove the old version. Still i cant remove the old version, although i'm able to execute the python 2.7.3 when i install any module i cant import it. I added the path to sys.path and i started finding the module but importing it causes another errors.
My python executes the /usr/local/bin/python which is the 2.7.3 version where the problems are.
If i try to execute python like this /usr/bin/python it executes the old version and everything works fine there, i can import the new installed modules.
So what can i do to make python 2.7.3 work?
I've searched a lot of tutorials and tried things like add the library in .pth files on python and i started finding the modules but when importing it i get errors like this:
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/numpy/__init__.py", line 137, in <module>
import add_newdocs
File "/usr/local/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "/usr/local/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 4, in <module>
from type_check import *
File "/usr/local/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "/usr/local/lib/python2.7/dist-packages/numpy/core/__init__.py", line 5, in <module>
import multiarray
ImportError: /usr/local/lib/python2.7/dist-packages/numpy/core/multiarray.so: undefined symbol: PyUnicodeUCS4_AsUnicodeEscapeString
Thanks for the help
EDIT PROBLEM SOLvED
So to solve the missing import modules i created a .pth file under /usr/local/lib/python2.7/site-packages/ with the directories where the python modules are and the python starts to find them.
To fix the comptability problems you can install python from sources and specify the unicode doing ./configure --enable-unicode
more information here
Do not EVER mess with system python, EVER.
What you should do is install python 2.7.3 with a --prefix into your home directory, then use virtualenv -p /home/myuser/path/to/python.
In any case, using virtualenv to run your own application is almost always a good idea, as it avoids polluting the system package directories with libraries you use in your own applications.
It looks like the modules you've installed were built against your old version of Python, or at least a version incompatible with your newer installation. The import error you're seeing at the bottom is the numpy module searching for a symbol that is not in your build of 2.7.3. There is further information here.
If possible, it's usually way easier to upgrade Python with a package manager. That way, if anything on your system depends on Python, but does not need exactly 2.7.2, then Python can be easily upgraded without disturbing anything. I'm guessing that either your server doesn't have a newer version of Python available and you can't add new repositories, or you don't have access to a package manager. If using packages is possible, I would go ahead and remove what you've built from source (the command should be 'make clean' if Python uses GNU Make).
If that isn't an option, then there should be a way to compile Python, but not install it into system directories. Then you could add a symlink for users, and make sure that symlink has precedence in their path.
When installing python use the following steps
using prefix to specify the installation directory
./configure --prefix=/usr/bin/python
make
make install
Then everytime u run a new Terminal u have specify
export PATH="$PATH:/usr/bin/"
to tell where is the installation directory of Python
This way u can use any number of pythons
You can install python libs from R. It works for me.
For example, to install numpy library from R type:
system('python -m pip install -U numpy')