Can't use cx_Freeze on my Windows 10 Machine - python

I am building a python script that I want to compile to a .exe file for anyone to be able to run. I'm attempting to follow the guide on this other question, and I instantly ran into issues.
I'm currently developing on Windows 10 through the use of VSCode (I've also tried this through Pycharm to the same issue). I successfully have installed cx_Freeze to the point where when I try to install it again I get Requirement already satisfied:
PS E:\code\scorekeeper> py -m pip install cx_Freeze
Requirement already satisfied: cx_Freeze in c:\users\beau\appdata\local\programs\python\python39\lib\site-packages (6.8)
Requirement already satisfied: cx-logging>=3.0 in c:\users\beau\appdata\local\programs\python\python39\lib\site-packages (from cx_Freeze) (3.0)
Requirement already satisfied: importlib-metadata>=4.3.1 in c:\users\beau\appdata\local\programs\python\python39\lib\site-packages (from cx_Freeze) (4.8.1)
Requirement already satisfied: zipp>=0.5 in c:\users\beau\appdata\local\programs\python\python39\lib\site-packages (from importlib-metadata>=4.3.1->cx_Freeze) (3.5.1)
The issue is, the Pylance plugin I have in VSCode shows an error on the import saying that "Import "cx_Freeze" could not be resolved".
And as expected, when I try to run the script, I get this error:
PS E:\code\scorekeeper> & e:/code/scorekeeper/.venv/Scripts/python.exe e:/code/scorekeeper/setup.py
Traceback (most recent call last):
File "e:\code\scorekeeper\setup.py", line 1, in <module>
from cx_Freeze import setup, Executable
ModuleNotFoundError: No module named 'cx_Freeze'
Anyone have any ideas on what's going on here?

The problem was that I was not in an integrated terminal using the .venv file in the project, because windows had errored when it tried to set the .venv as the active terminal due to Execution policies. Once I gave the terminal permissions to run scripts and re ran the activate it was able to install the package.
It had installed the package to the python root PATH, but was using the interpreter in the .venv folder in the project.

Related

PyCharm No module named 'nltk' even though I've installed it using pip3?

import nltk
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'nltk'
This is the error that I get from running PyCharm 2021.3.2 (Community Edition).
However, when I go to my terminal and try
pip3 install nltk
I see that
Requirement already satisfied: nltk in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (3.7)
Requirement already satisfied: click in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from nltk) (8.1.3)
Requirement already satisfied: regex>=2021.8.3 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from nltk) (2022.9.13)
Requirement already satisfied: joblib in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from nltk) (1.2.0)
Requirement already satisfied: tqdm in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from nltk) (4.64.1)
So it seems that I've already installed nltk? But why is PyCharm still giving me that error? I'm using macOS Monterey 12.6 if that helps with anything.
Some things to try:
On your terminal, check which on which python environment you're using your script. It's a common source of headaches that using python 2.7 and python 3.x would not work for packages only installed with either pip or pip3. On the terminal do
python --version
and (if available)
python3 --version
And check if you can make it work after installing the same package with pip (as opposed to pip3).
using conda as a package manager can lead to millions of conflicts across your system. Are you by any chance using conda/anaconda? If so, you should try intalling the package with conda instead of pip.
check that whatever python you're using, it can reach the location of wherever you installled PyCharm.
Check if your package was installed locally as opposed as globally. For the former, do pip list on your terminal. For the latter, do pip list --user instead.

How can i install python modules that have spaces in between?

I wanted to run a script that would scan my network and that script uses a awesome library called who-is-on-my-wifi. I have installed the module to run the script but i get errors from the prompt saying that it cannot detect such a module in the system.
This is the script.
from who_is_on_my_wifi import *
WHO = who()
for i in range(0, len(WHO)):
print(WHO[i])
And this is the error that i get.
python scanner.py
Traceback (most recent call last):
File "scanner.py", line 1, in <module>
from who_is_on_my_wifi import *
ImportError: No module named who_is_on_my_wifi
This is the proof that i have installed the module
pip3 install 'who_is_on_my_wifi'
Requirement already satisfied: who_is_on_my_wifi in /home/harein/.local/lib/python3.8/site-packages (1.2.0)
Requirement already satisfied: getmac in /home/harein/.local/lib/python3.8/site-packages (from who_is_on_my_wifi) (0.8.2)
Requirement already satisfied: python-nmap in /home/harein/.local/lib/python3.8/site-packages (from who_is_on_my_wifi) (0.6.1)
Any suggestions on how i can avoid this can continue executing my script ?
EDIT
The script finally executed the way i want by changing the,
python scanner.py to python3 scanner.py
You guys were right, it was the way how i executed the script that generated this error and it was not a problem in the module apparently.
I would like to thank everyone who gave the support.<3
When trying to
import this_is_not_a_module
the error you get:
ImportError: No module named this_is_not_a_module
is the error raised by Python 2.
Python 3 would raise a different one:
ModuleNotFoundError: No module named 'this_is_not_a_module'
So, your actual problem is that your system tries to execute your script with some Python 2 version, while you installed your module for your Python 3.8 version.
sometimes you can't import modules because you have installed two python versions(or conda along with it). if you have, delete one of your python versions or activate conda and try importing your module, or just try:
pip uninstall who_is_on_my_wifi
pip install who_is_on_my_wifi
I usually tend to install modules per project and use virtualenv for it.
It kind of links respective versions of programs (like python interpreter, pip and so on) and takes care of PYTHONPATH and the way of installed dependencies.
$ pip3 install virtualenv
$ virtualenv whoisonwifi
$ source whoisonwifi/bin/activate
$ pip --version
pip 21.0.1 from
/mnt/devel/workonhome/whoisonwifi/lib/python3.7/site-packages/pip
(python 3.7)
$ pip install 'who_is_on_my_wifi'
from there your code (sort of) works for me.

VS Code: Unable to install flask

I'm not using a virtual environment, & have tried selecting the appropriate python interpreter.
When I do a python3 -m pip install flask,
my terminal says Requirement already satisfied: MarkupSafe>=0.23 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from Jinja2>=2.10.1->flask) (1.1.1)
However, I receive this error message: ModuleNotFoundError: No module named 'flask' which traces back to VSCode being unable to import "flask" for some reason.
Would appreciate any help!

keep getting python ModuleNotFoundError: No module named

I am working on a raspberry pi python project and every time I import a package I get the same error ModuleNotFoundError: No module named ''. for example I am trying to add the ambient_api package
I followed the steps in their set up:
pip install ambient_api
Added the imports at the top of my file:
from ambient_api.ambientapi import AmbientAPI
api = AmbientAPI()
but I am getting the error:
ModuleNotFoundError: No module named 'ambient_api'
This is happening with all the imports I am trying to add and I cant figure out what I am missing.
when I was looking on google I came across __init__.py might be a solution but I am not sure how this works?
edit:
here is what was output when I installed:
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: ambient_api in /home/pi/.local/lib/python2.7/site-packages (1.5.2)
Requirement already satisfied: requests in /usr/lib/python2.7/dist-packages (from ambient_api) (2.21.0)
Requirement already satisfied: urllib3 in /usr/lib/python2.7/dist-packages (from ambient_api) (1.24.1)
version in my terminal:
pi#raspberrypi:~/Raspberry-Pi-Greenhouse $ python --version
Python 2.7.16
but it looks like the version in the shell in the ide when I run the program is saying:
Python 3.7.3 (/usr/bin/python3)
As explained by #JaFizz in Pytorch is installed but do not working ubuntu 18.04 it solved by giving an alias and installing correctly to desired python version (there were two pythons installed on the same machine)
First it was necessary to specify the location of the python, example:
alias python=/usr/local/bin/python3.6
Then install it:
python pip install <package name>

PyInstaller won't install, Python 3.6.0a4 and x64 Windows

I have said Python version (from https://www.python.org/downloads/windows/), and x64 Windows 10.
Every time I try to execute "pip install pyinstaller" it crashes with an error:
C:\WINDOWS\system32>pip install pyinstaller
Collecting pyinstaller
Using cached PyInstaller-3.2.tar.gz
Requirement already satisfied (use --upgrade to upgrade): setuptools in c:\users\jskurski\appdata\local\programs\python\python36\lib\site-packages (from pyinstaller)
Collecting pefile (from pyinstaller)
Using cached pefile-2016.3.28.tar.gz
Collecting pypiwin32 (from pyinstaller)
Using cached pypiwin32-219.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\jskurski\AppData\Local\Temp\pip-build-y9lsbd5f\pypiwin32\setup.py", line 121
print "Building pywin32", pywin32_version
^
SyntaxError: Missing parentheses in call to 'print'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\jskurski\AppData\Local\Temp\pip-build-y9lsbd5f\pypiwin32\
So, for me it seems there is a version msmatch or something. Unofortunately, I can not figure it out myself.
Any suggestions?
Has anybody sucessfully used PyInstaller with latest 3.6 Python on Windows? Or maybe I should downgrade Python to older version?
edit: tested on another PC (same enviroment) and it was the same.
edit2: seems to work on 3.5.2 version, so it's probably a way to go, for now.
pyinstaller needs pypiwin32 module.
when pip tries to install it, it shows an error because there is no pypiwin32 for python3.6
Case is closed for me, as I downgraded to stable 3.5.2. Probably some inconsistency in that alpha release, which caused this. I just wanted to write a simple GUI Windows program, so I will not investigate further.
You have to install manually pywin32 according to your version of python. The following link you can download.
https://sourceforge.net/projects/pywin32/files/pywin32/Build%20221/
Once installed pywin32 with your right version of python. Pyinstaller must be installed
As cdarke pointed out, you are running python 2 code on Python 3.
Try this instead:
pip3 install pyinstaller

Categories

Resources