I need to use numpy and matplotlib modules in my scripts. However, program crashes with ModuleNotFoundError. But when i run pip freeze those module names show up. When i'm trying to import them in the python command line it doesn't throw any exception. I ran print(sys.path) command and found those modules in the list of folders that it returned. Why they can't be imported in my script?
Related
I have tried to put this script in the sitecustomize.py file, to be able to see colored error messages in visual studio code.
the script:
import sys
from IPython.core.ultratb import ColorTB
sys.excepthook = ColorTB()
I got the error message above even though I have used pip to install ipython.
EDIT:
I tried to use coloredlogs instead of ipython and it showed me the same message again
The IPython module only works inside iPython, not inside any other IDE/Shell/etc.
Please use the command "pip show ipython" to check the installation location of the module:
(If it does not display the location of the module, it means that the terminal used environment is inconsistent with the selected one.)
Then find the folder of the module in this python environment, try to delete it, and then reinstall it:
Run:
I needed to reinstall python on my computer. there were multiple versions of it, and because of that there were multiple versions of pip
I am having trouble installing a package through its directory (not possible to install through pip, only folder available) on my mac.
I am using a python 2.7 environment on Conda and did the following after reading many posts and tutorials:
decompressed the file with the modules I need ("/Users/personal/python_files/PyOPC-0.1/PyOPC")
used the command conda develop "path/to/PyOPC" on the terminal
added the following line to the bottom of the ~/.bash_profile file: export PYTHONPATH="/path/to/PyOPC"
checked my sys.path through python2 -c "import sys; print('\n'.join(sys.path))" on the terminal
When I do the latter, I can see the path to PyOPC listed there, so I thought I wouldn't have problems importing any modules.
Nonetheless, when I run my code I get the following:
from basic import BasicXDAServer
ImportError: No module named basic
basic.py is a file inside the folder PyOPC/servers. If I move "basic" to the main PyOPC folder, I get a different import error referring to an import happening within basic.py...
Here is the complete directory I am referring to available on Github: https://github.com/ibh-systems/pyopc/tree/master/PyOPC
Is there a problem with the structure of the directory itself or did I do something wrong as I installed it. Thanks for the help.
I'm trying to run my python script that I developed/tested through IDE and it's working fine over there.
But when I try to run the same script on Command Prompt (Windows 10) which has to import any module. Note that python script and the .bat file is in the same directory.
I think this is happening environment setup so I did some search and found these posts below;
import error: 'No module named' *does* exist
No module error when running python script from command prompt
Python command line Import Error
Unable to imoprt modules on python script while running on cmd
Package doesn't work if run from cmd or from the .py file.... PYTHON
https://www.programmersought.com/article/7436148385/
Here is the error snapshot
Steps followed
Python version 3.8.3
Environment variables are set under system environment variables
in the 'code.py' also added
import sys
sys.path.append('D:\program_files\anaconda3\Lib\site-packages')
Seaborn and Scipy updated the latest versions
CMD FILE look like this
I followed older solutions like set up environment variables for python libraries and python path so for not even close to get rid of this error.
Any idea to help what I'm missing here ?
Thanks
The Problem
I have a Python script that runs in the background. At some point the script tries to import a module: import mymodule.
Before the import line is executed in the Python script, another bash script (successfully) installs mymodule by running python setup.py install.
The problem is that import mymodule in the Python script is not working because mymodule is not found, even though it's installed.
My solution
I checked sys.path before installing mymodule and after I saw that a new line had been added: /usr/lib/python2.7/dist-packages/mymodule-1.0py.egg. So before the line importing the module I added the line sys.path.append("/usr/lib/python2.7/dist-packages/mymodule-1.0py.egg").
My question is whether there is a better, less hardcoded way to solve the problem.
You will have to refresh the sys.path
but you can use the site.py to do it.
import site
reload(site)
I'm facing a strange problem in Python imports. I've written a simple Python module, called test.py. It contains:
import wx
When I run this code in IDLE, it runs successfully. But when I run the same module through command-line, it gives me an ImportError: no module named wx.
It is not an error related to wx library for two reasons. One, because it runs on IDLE. And two, I'm unable to run any module with an import statement in command-line.
PS: I've set all the environment variables. (C:\Python27\; C:\Python27\Scripts).
What may be the problem?
You should run the command line under your script folder.
For instance,
Your test.py was under the folder: ~/scripts/test.py,
then you should first change to this folder: cd ~/scripts
and run the python command-line: python or python test.py.
The reason is that:
You IDE has already changed to your file folder, since you can run it.
But the command-line was not.
Hope this helps.