I'm trying to use Pybuilder to build and then run my python project unittests. Everything goes well in the build process, but when it goes to run my unittests I receive the following error message:
File "/Users/username/Desktop/Work/pythonutilities/tests/test_elastic_controller.py", line 5, in <module>
from src.elastic_controller import ElasticController
ModuleNotFoundError: No module named 'src'
It can't seem to import the src module.
However, if I then create a task that executes a separate setup.py install (via command line using the subprocess library), it works perfectly. Pybuilder should be creating and installing it's own setup.py though, correct? So this shouldn't be a problem or a suitable solution.
I'm not sure where to go next, any help would be appreciated.
Related
I am new to python and trying to run code from existing project. I am getting the below error:
Traceback (most recent call last):
File "/xxxx/xxxx/Library/Application Support/JetBrains/IdeaIC2021.1/plugins/python-ce/helpers/pycharm/_jb_pytest_runner.py", line 2, in <module>
import pytest
ModuleNotFoundError: No module named 'pytest'
The file is present in the mentioned path.
I see that there are many questions regarding this but nothing seems to provide me with a solution.
I am using the IntelliJ IDEA IDE.
The error message is telling you that File "/xxxx/xxxx/Library/Application Support/JetBrains/IdeaIC2021.1/plugins/python-ce/helpers/pycharm/_jb_pytest_runner.py" is trying to import pytest but fails to find the package. That is, it's not the presence of that file that's failing, but that it can't find pytest in order to import it.
Install pytest using
python3 -m pip install pytest
Change python3 accordingly to use the specific installation of python that you're using in the IDE.
This is because you don't have the needed environment.
Since you use the Pycharm, you can try to install pytest.
https://blog.finxter.com/how-to-install-a-library-on-pycharm/
This worked for me. Repeating here:
Open IntelliJ's settings/preferences
Go to Tools -> Python Integrated Tools
Under Testing...Default test runner: choose pytest
Click the Fix button that appears in the bottom of the panel
I am having an issue with python not being able to find or import my module. I am unsure how to fix this problem. My py file I'm trying to get my import into is in 'main' folder, the file I'm trying to import is one level up. My program is a package:
Error I'm getting
models.py
Trying copying your .py file to site-packages folder present in the Python folder and then running your python file from command prompt(python -m <your_file_name>.py)/python launcher/IDE. In case you are still getting the error then share your code as well so that people can see.
I created a project in Pycharm including a gp.py, copied the project folder to another machine and tried to run the gp.py script from command line using python gp.py. However I got a error
Traceback (most recent call last):
File "gp.py", line 2, in <module>
from gplearn.genetic import SymbolicRegressor
ModuleNotFoundError: No module named 'gplearn'
The thing is I could see this gplearn library I used in the project folder, like below. The screen shot is not from Pycharm but the folder I copied to another computer. I tried to place the gp.pyinside and outside venv folder but neither worked. Could you please help to point out what the problem is ? Many thanks
gplearn package is not installed in the new machine.
Go to cmd prompt/terminal in pycharm and execute below line:
pip install gplearn
Sound like you are seeking for a method to deploy your script to end user, in this case maybe you can give Pyinstaller a try.
I have a python package that involves several python modules. The project has been created in pycharm. I have used pyinstaller to create a single executable file of my python package. When I run the executable using a batch file I get an import error, specifically pandas has failed to be imported. Is there a reason why pyinstaller has not also collected the package dependencies in my virtual environment?
Thanks in advance for any help!
I have the following 2 errors:
(1) ModuleNotFoundError: No module named 'pandas._libs.tslibs.np_datetime'
(2) File "site-packages\pandas__init__.py", line 35, in
ImportError: C extension: No module named 'pandas._libs.tslibs.np_datetime' not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first.
There is one pip script for each virtual environment. So when you install a python module it get installed into the projectname\venv\Lib\site-packages directory.
When you run pyinstaller from terminal to make the executable, pyinstaller checks for dependencies in Sys.path . But that path does not include the projectname\venv\Lib\site-packages directory. Therefore pyinstaller cannot find those particular dependencies. In such cases it gives you warnings.Those warning can be found in 'warnname.txt' near your executable file.
EDIT: How to Configure pycharm to run pyinstaller
First you need to add pyinstaller into project interpreter.
Then you need to setup running configurations.
Script name: path to your python script
working path: Project location
leave interpreter options as it is in the image.
Run pyinstaller. You can find your .exe in dist directory.
If the "Module not found" error still persists. You can add a hidden import hook and specify the names of the missing modules.Navigate to
Project Path\venv\Lib\site-packages\PyInstaller\hooks
and create a new "hook-pandas.py"(hook-modulename.py) script and make a list of hidden import modules like this.
hiddenimports = ['pandas._libs.tslibs.np_datetime','pandas._libs.tslibs.nattype','pandas._libs.skiplist']
And run pyinstaller again, and it should work now.
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.