Hi I generated a pyc with python -m compileall file.py
The program works in Pycharm and pandas is installed in venv but when I launch the pyc without the venv interpretor or on another machine it says Module not Found.
Panda module is found when I install pandas outside the venv.
Do I have to do pip install all modules on every environment or is there a way for the .pyc to work without installing modules on the host ?
project
$ python PXAGIRA01.cpython-37.pyc
Traceback (most recent call last):
File "_SOURCES/PXAGIRA01.py", line 4, in
ModuleNotFoundError: No module named 'pandas'
Related
I´ve installed and uninstalled pygame several times, I tried with pip/pip3 and still appears the following error:
Traceback (most recent call last):
File "c:\Users\josel\Desktop\Programación\Python\pygame\test\main.py", line 3, in <module>
import pygame
ModuleNotFoundError: No module named 'pygame'
I also executed "pip install pygame" in the vsc terminal and gave this message:
Requirement already satisfied: pygame in c:\users\josel\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (2.0.1)
Edit:
The output of
import sys
print(sys.path)
is:
['c:\\Users\\josel\\Desktop\\Programación\\Python\\pygame\\test', 'C:\\Users\\josel\\AppData\\Local\\Programs\\Python\\Python39\\python39.zip', 'C:\\Users\\josel\\AppData\\Local\\Programs\\Python\\Python39\\DLLs', 'C:\\Users\\josel\\AppData\\Local\\Programs\\Python\\Python39\\lib', 'C:\\Users\\josel\\AppData\\Local\\Programs\\Python\\Python39', 'C:\\Users\\josel\\AppData\\Roaming\\Python\\Python39\\site-packages', 'C:\\Users\\josel\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages', 'C:\\Users\\josel\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\win32', 'C:\\Users\\josel\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\win32\\lib', 'C:\\Users\\josel\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\Pythonwin']
A short way to fix this is using a venv
python3 -m venv venv
source ven/bin/activate
pip install pygame
keep the venv activated when you run the code
use
which python # check if VSC is using the right interpreter
I am building a web scraper and I am trying to import the 'requests' package but I am getting an error. I am being told the following:
ModuleNotFoundError: No module named 'requests'
Full Error:
(venv) USERs-MacBook-Pro:Scraper user$ /usr/local/opt/python#3.9/bin/python3.9 /Users/user/git/ML/Python/Practice/Scraper/Scraper.py
Traceback (most recent call last):
File "/Users/user/git/ML/Python/Practice/Scraper/Scraper.py", line 1, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
Steps I took when setting up project:
python3 -m venv project_name/venv
source project_name/venv/bin/activate
python3 -m pip install SomePackage
Confirmation package and dependences were installed:
(venv) USERs-MacBook-Pro:Scraper user$ pip list
Package Version
---------- ---------
certifi 2020.12.5
chardet 4.0.0
idna 2.10
pip 20.2.3
requests 2.25.1
setuptools 49.2.1
urllib3 1.26.2
By using the absolute path to system Python like that:
/usr/local/opt/python#3.9/bin/python3.9 /Users/user/git/ML/Python/Practice/Scraper/Scraper.py
you are using system's Python 3.9 and the packages that are installed for that one although you are in a virtual environment.
When creating a virtual environment you are creating a separate environment with the specified python version and all the packages you install with pip are installed to this environment and this python version.
You can better understand that if you run:
which python
inside your virtual environment.
This will show you the python that is used when you run python inside your venv and it's going to be different than
/usr/local/opt/python#3.9/bin/python3.9
So, by having installed requests using pip inside your environment, it is installed in the environments python which is executed when you run just python.
To sum up, to use the packages installed inside your venv with pip you should run your script (after activating the venv) with:
python /Users/user/git/ML/Python/Practice/Scraper/Scraper.py
I'm trying to turn my python project into .exe
I used : pyinstaller --onefile main.py
Then I moved the main.exe into the original file to be sure it can access all the dependencies.
When I run the main.exe, I get an error, failed to execute script main.
I typed cmd in the directory of the python project, and tried python main.py
It gave me this error :
Traceback (most recent call last):
File "main.py", line 3, in <module>
from PyQt5 import QtWidgets, QtCore
ModuleNotFoundError: No module named 'PyQt5'
Even though every module are installed, why is it telling me that?
Thank you.
You haven't installed pyqt5.
Try pip install pyqt5 or pip3 install pyqt5
for linux
sudo apt install python3-pyqt5
I did a fresh python3 installation on OSX via homebrew:
brew install python3
Then I created a virtual environment for my project and installed scipy and scikits.samplerate:
virtualenv -p /usr/local/bin/python3 pythen_env
pip install scipy
pip install scikits.samplerate
However, when I try to import a function from scikits.samplerate, I get the following error:
>>> from scikits.samplerate import resample
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/my/project/path/pythen_env/lib/python3.6/site-packages/scikits/samplerate/__init__.py", line 4, in <module>
from info import __doc__
ModuleNotFoundError: No module named 'info'
Info happens to be the first module from the package itself that is imported in __init__.py.
Strangely, the module info.py exists in /my/project/path/pythen_env/lib/python3.6/site-packages/scikits/samplerate/:
ls /my/project/path/pythen_env/lib/python3.6/site-packages/scikits/samplerate/
__init__.py setup.py tests __pycache__
info.py setuphelp.py version.py
The error also happens when I try the same without virtualenv, as well as for other packages. How could I start to debug this issue?
The problem seems to be that the package scikits.samplerate does not support Python 3.X (see issue). However, there is a fork which supports Python 3.X. You can install it via
$ pip install git+https://github.com/gregorias/samplerate.git
As always: people can make anything they like in repositories. I did not check which changes gregorias made.
the git version does support py3
https://github.com/cournape/samplerate
(merged the PR from #gregorias)
I should find the time and procedure to update pypi too...
I am trying to use Pexpect for a python script I am writing with python 3. I tried installing the module on commmand prompt with admin privileges by using the pip install command:
pip install Pexpect
Once the module finished installing I opened IDLE and in it and tried importing the module:
import pexpect
which gave the error:
Traceback (most recent call last):
File "", line 1, in
import pexpect
ImportError: No module named 'pexpect'
The problem is python cant see the imported module even after its installation.How can i prevent this from happening?
This might occur if you have multiple versions of Python installed on your machine. Assuming you have Python 2.7 and 3 installed, I am guessing "pip" installed pexpect under the 2.7 libraries. Easiest way around this is to add the path to your Python 2.7 packages to your sys.path.
import sys
sys.path.append('/usr/lib/python2.7/dist-packages')
The path mentioned above tends to change depending on your Python installation. So make sure to validate the path before running your script.
Alternatively, you could use pip3 to install packages for Python 3 directly. Please refer this question for instructions.