pwntools Python module doesn't work in python2 but works in python3 - python-import

I have a python2 script I want to run with the pwntools python module and I tried running it using:
python test.py
But then I get:
File "test.py", line 3, in
from pwn import *
ImportError: No module named pwn
But when I try it with python3, it gets past that error but it runs into other errors because it's a python2 script. Why does pwntools not work when I run it with python2 and can I get my script to run without porting the whole thing to python3?

Hard to say for sure but it looks like you installed pwntools for python3 and not for python2. Packages are not shared between python versions. if you run python2 -m pip install --user pwntools and then try to run with python2 does it work?

Yeah even I had faced this issue. Try installing pwntools using sudo pip install pwntools.

Related

Error when installing the pyqt5 package into docker image (Host: mac os m1) [duplicate]

A program I am trying to install requires the installation of PyQt5 5.15.0 , which gives me this error. The odd thing is that the installation works fine for the latest version of PyQt5 (5.15.2), but this program requires 5.15.0 specifically.
Command Output:
Collecting PyQt5==5.15.0
Using cached PyQt5-5.15.0.tar.gz (3.3 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... error
ERROR: Command errored out with exit status 1:
command: 'c:\users\mshal\appdata\local\programs\python\python39\python.exe' 'C:\Users\mshal\AppData\Roaming\Python\Python39\site-packages\pip\_vendor\pep517\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\mshal\AppData\Local\Temp\tmp41s11ev6'
cwd: C:\Users\mshal\AppData\Local\Temp\pip-install-sfw90hvc\pyqt5_e2cc46859b554da7b84798abae5378ba
Complete output (31 lines):
Traceback (most recent call last):
File "C:\Users\mshal\AppData\Roaming\Python\Python39\site-packages\pip\_vendor\pep517\_in_process.py", line 126, in prepare_metadata_for_build_wheel
hook = backend.prepare_metadata_for_build_wheel
AttributeError: module 'sipbuild.api' has no attribute 'prepare_metadata_for_build_wheel'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\mshal\AppData\Roaming\Python\Python39\site-packages\pip\_vendor\pep517\_in_process.py", line 280, in <module>
main()
File "C:\Users\mshal\AppData\Roaming\Python\Python39\site-packages\pip\_vendor\pep517\_in_process.py", line 263, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "C:\Users\mshal\AppData\Roaming\Python\Python39\site-packages\pip\_vendor\pep517\_in_process.py", line 130, in prepare_metadata_for_build_wheel
return _get_wheel_metadata_from_wheel(backend, metadata_directory,
File "C:\Users\mshal\AppData\Roaming\Python\Python39\site-packages\pip\_vendor\pep517\_in_process.py", line 159, in _get_wheel_metadata_from_wheel
whl_basename = backend.build_wheel(metadata_directory, config_settings)
File "C:\Users\mshal\AppData\Local\Temp\pip-build-env-nnx_yu09\overlay\Lib\site-packages\sipbuild\api.py", line 51, in build_wheel
project = AbstractProject.bootstrap('pep517')
File "C:\Users\mshal\AppData\Local\Temp\pip-build-env-nnx_yu09\overlay\Lib\site-packages\sipbuild\abstract_project.py", line 83, in bootstrap
project.setup(pyproject, tool, tool_description)
File "C:\Users\mshal\AppData\Local\Temp\pip-build-env-nnx_yu09\overlay\Lib\site-packages\sipbuild\project.py", line 479, in setup
self.apply_user_defaults(tool)
File "project.py", line 62, in apply_user_defaults
super().apply_user_defaults(tool)
File "C:\Users\mshal\AppData\Local\Temp\pip-build-env-nnx_yu09\overlay\Lib\site-packages\pyqtbuild\project.py", line 79, in apply_user_defaults
super().apply_user_defaults(tool)
File "C:\Users\mshal\AppData\Local\Temp\pip-build-env-nnx_yu09\overlay\Lib\site-packages\sipbuild\project.py", line 225, in apply_user_defaults
self.builder.apply_user_defaults(tool)
File "C:\Users\mshal\AppData\Local\Temp\pip-build-env-nnx_yu09\overlay\Lib\site-packages\pyqtbuild\builder.py", line 66, in apply_user_defaults
raise PyProjectOptionException('qmake',
sipbuild.pyproject.PyProjectOptionException
----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\mshal\appdata\local\programs\python\python39\python.exe' 'C:\Users\mshal\AppData\Roaming\Python\Python39\site-packages\pip\_vendor\pep517\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\mshal\AppData\Local\Temp\tmp41s11ev6' Check the logs for full command output.
I am on the latest version of pip. Any ideas on the root cause of this issue?
What helped me is upgrading pip from 20.2.3 to the latest one (in my case 21.1.1)
For Mac/Homebrew users.
The answer by #the-x is leading in the right direction. On a Mac with QT5 installed via Homebrew the qmake binary just needs to be added to the path. This can be achieved through
export PATH="/opt/homebrew/opt/qt5/bin:$PATH"
(of course depending on where the homebrew files are installed)
Running on arm with python3.6 (ubuntu18 on nvidia Xavier):
sudo apt install qt5-default
For MacOS users.
I am on Apple M1 silicon using Python 3.9.8. What worked for me was #Apaul's comment in the original question section. Install pyqt5-sip prior to pyqt5.
I also have an Intel Mac and on that machine, I do not need to do this.
Checking the binaries that PyQt5 provides in pypi for version 5.15.0 I see that it does not provide the binaries for python3.9 in windows, so pip is trying to compile using the source code which is complicated and can generate several dependency problems (for example you must have Qt 5.15 installed, etc). So my recommendation is to install a more updated version of PyQt5, for example 5.15.2 since if it provides the binaries for python3.9 on windows, in addition to being a wrapper of an LTS version of Qt then it will have solved several bugs.
python -m pip install PyQt5==5.15.2
Another solution is to use python3.8 instead of python3.9 so that you can install pyqt5 5.15.0 from pypi without problems.
Upgrading your pip enables you to install PyQt5. Personally, I had the same issue while installing PyQt6 and I upgraded my pip, and everything installed perfectly. I think both python and pip versions play an important role in installing PyQt so make sure you have later versions.
This is the command I used in Linux:
pip install --upgrade pip
Combining several answers on this question: On an Apple M1 Pro Macbook with macOS Ventura 13.0.1, with Homebrew 3.6.17 and python 3.11.0 the following commands fixed it for me (no sudo):
brew install qt5
export PATH="/opt/homebrew/opt/qt5/bin:$PATH"
python3 -m ensurepip --default-pip
pip3 install pyqt5-sip
pip3 install pyqt5 --config-settings --confirm-license= --verbose
That last step calls qmake to compile all of Qt on your M1 and takes many minutes to complete, be patient and let it finish.
Since qt5-default was not available, I installed qt5-default's dependencies
sudo apt-get install qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools
after that I installed pyqt5 via apt-get first and afterwards via pip
sudo apt-get install pyqt5-dev
pip install pyqt5
now wheel seems to work
side-note:
I am not sure if sudo apt-get install pyqt5-dev is even necessary
The error message thrown here is misleading - it's not an issue with a sipbuild.api attribute. Indeed, in this case program qmake is missing, see last line of the Python traceback. Have a look if it's installed on your system and add it to your PATH variable. Otherwise, install it. On Linux this would be done with
sudo apt-get install qt5-qmake
I had this problem on my M1 Mac using Python 3.9.12 when I was trying to install a library: pip install pixellib.
The first thing I did was: pip install pixellib --verbose to see the whole log, and there I noticed that PyQt5 was waiting for an input. So then I found someone else with that issue, and used pip install pyqt5 --config-settings --confirm-license= --verbose which took some time to compile, but worked!
I could not get any of the above solutions to work but I managed to get it working using python3.9, PyQt5=5.15.2, pip=22.0.2 and sip=6.5.0 by using sudo apt-get install PyQt5. If you need it in a virtual environment, you can manually copy the PyQt5 folder from your default /usr/lib/python3/dist-packages to the site-packages folder in your virtual environment.
To all those that are struggling with Apple M1 installation, here is a working solution, specifically addressing the problem of installing the pixellib library that depends on PyQt5 but you can apply it equally to other libs:
PyQt5 is not supported on Apple M1, it needs qt6: https://www.reddit.com/r/learnpython/comments/o4w1ut/comment/h2jele3/?utm_source=share&utm_medium=web2x&context=3 , https://www.qt.io/product/qt6
this means you need to install PyQt6: python3 -m pip install PyQt6
go to the lib you need, in my case pixellib: https://pypi.org/project/pixellib/#files and
download the wheel file
get the wheel tool: pip install wheel
unpack the wheel wheel unpack pixellib-0.7.1-py3-none-any.whl
Change its dependency of PyQt5 to PyQt6
edit pixellib-0.7.1/pixellib-0.7.1.dist-info/METADATA
pyQt5 => pyQt6
pack it back wheel pack pixellib-0.7.1
install it: pip install pixellib-0.7.1-py3-none-any.whl
test in python: `
# should work
import pixellib
P.S. thanks to Terra and ChaOS for supporting work on the project underlying this report.
I finally managed to make it works on M1/M2 Macbook Pro.
None of these answers worked for me, so I looked at brew to install pyqt.
The following command will install pyqt5 via brew:
brew install pyqt#5
Then it just worked.
This can be resolved by switching to an environment with Python >= 3.8

preparing metadata (setup.py): finished with status 'error' [duplicate]

Trying to install:
pip install multiprocessing
Getting an error:
Collecting multiprocessing
Using cached multiprocessing-2.6.2.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/7s/sswmssj51p73hky4mkqs4_zc0000gn/T/pip-build-8c0dk6ai/multiprocessing/setup.py", line 94
print 'Macros:'
^
SyntaxError: Missing parentheses in call to 'print'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/7s/sswmssj51p73hky4mkqs4_zc0000gn/T/pip-build-8c0dk6ai/multiprocessing/
Anyone knows the way to fix this?
In short: Multiprocessing is already pre-installed in python 3, no need to install it.
I found an answer to my question and it's a silly one - multiprocessing is already pre-installed in my version of Python (3.5.2) by default.
It won't show up in the list of packages in Anaconda >> Environments >> root, as it's not a third party package but an internal one.
If anyone is not sure whether this applies to you, just check from multiprocessing import Pool in your Python console.
This is true of all currently supported versions of Python (2.7 and 3.x) and according to a Python maintainer/contributor multiprocessing has been part of the standard library (batteries included) since Python 2.6. https://bugs.python.org/msg326646
You won't need to do a pip install multiprocessing anymore and do NOT include it in your requirements.txt unless you are maintaining a Python 2.4/2.5 application (please migrate!). On most versions you can just import multiprocessing and you should be fine.
Instead of pip install multiprocessing type instead:
pip install multiprocess
Of course you are trying to install multiprocessing library on python3 while this library is installed on python3 by default and doesn't need to install again.
Be Lucky
pip3.5 install multiprocessing-utils
https://pypi.org/project/multiprocessing-utils/
python -m pip install multiprocessing
Use python2.7 to install multiprocessing instead of using python3.5+
Python 2.7 to 3 changed from print "Hello World" to print('Hello World') making print a function now. Judging from the error message, it looks like pip or multiprocessing is expecting python 3.
You can check your Python version using this command:
python --version
You update pip if you already have python 3 on linux:
sudo apt-get install python3-pip
For mac, you can use the equivalent homebrew command. This should allow you to use a:
pip3 install multiprocessing

Couldn't import cv2 in SageMaker Studio Lab

I tried importing cv2 from opencv but i got error saying
import error: libgthread-2.0.so.0: cannot open shared object file: No such file or directory
Since Sagemaker Studio Labs doesn't support installation of Ubuntu packages i couldn't use apt-get or yum to install libglib2.0-0.
You fix this by:
!pip uninstall opencv-python -y
Then use the headless version instead with studio:
!pip install opencv-python-headless
Ref: https://github.com/aws/amazon-sagemaker-examples/issues/1773
With this line, you can install the glib dependency for Amazon Sagemaker Studio Lab. Just run it on your notebook cell.
! conda install glib=2.51.0 -y
You also can create another virtual environment for your session that contains glib:
! conda create -n glib-test -c defaults -c conda-forge python=3 glib=2.51.0` -y
After that maybe you need albumentations to import cv2:
! pip install albumentations

Raspberry PI 4 - 8GM RAM - 64 bit OS aarch64 - easyocr - torch - opencv - illegal instruction

I am trying to get easyocr running on a raspberry pi 4 and could use some suggestions or help. I am using the 64 bit build from May 7th - 2021 (2021-05-07-raspios-buster-arm64.zip). When I do a fresh OS install, I execute the following commands:
sudo vi /etc/dphys-swapfile # change swapfile to 2GB
sudo raspi-config # expand the filesystem to use the entire SD card
sudo apt-get update #
sudo apt-get upgrade #
sudo apt autoremove # The following packages will be REMOVED: python-colorzero
sudo python -m pip install --upgrade pip # upgrade pip
sudo pip3 install --upgrade pip # upgrade pip3
sudo python3 -m pip install numpy --upgrade # upgrade numpy
sudo python3 -m pip install easyocr # install easyocr
I open a python3 editor and execute the following commands:
import cv2
import torch
import easyocr
reader = easyocr.Reader(['en'])
results = reader.readtext('/home/pi/Downloads/Calibration.bmp')
The last command results in an Illegal instruction error. I figured openCV was the likely culprit so I compiled it from source and tried again. I got the same error. I have tried going with a 32 bit build, but torch needs 64 bit to work. I have tried the same sequence and code through Anaconda on a windows 64 bit machine and it works without issue.
My next two attempts will be to build easyocr and/or torch from source , but I am grasping at straws here. I am really not sure how to figure out what software is causing the illegal instruction so I can hone in on that package. I would appreciate any thoughts on what I can do to get more information or thoughts on what things I can try.
Thanks a bunch.
[EDIT]I installed python3-dbg so I could run the application under gdb. When I do, the error I get is
Thread 1 "python3-dbg" received signal SIGILL, Illegal instruction. 0x0000ffffe4189fc8 in exec_blas () from
/home/[USER]/.local/lib/python3.8/site-packages/torch/lib/libtorch_cpu.so
[EDIT2]I found a git hub repository that creates wheel files (WHL) for those having illegal instruction errors like me. So far it hasn't helped. I have tried a few, but am going to use a more systematic approach. to see if I can find the right combination.

ImportError('Could not import PIL.Image. ' working with keras-ternsorflow

I'm following some lectures from lynda.com about deep learning using Keras-TensorFlow in a PyCharmCE enviroment and they didn't have this problem.
I get this error:
raise ImportError('Could not import PIL.Image. '
ImportError: Could not import PIL.Image. The use of array_to_img requires PIL.
I have checked if others get the same error, but for me installing pillow using pip with the command pip install Pillow doesn't solve anything.
MacBook-Pro-de-Rogelio:~ Rogelio$ pip install Pillow
Requirement already satisfied: Pillow in ./anaconda3/lib/python3.6/site-packages
MacBook-Pro-de-Rogelio:~ Rogelio$
Any solution?
All you need to do is install pillow:
pip install pillow
Then you should be all set. Found this after hours of searching.
I had the exact same error and I fixed it the following way:
1) Run this command in your Jupyter Notebook:
import sys
from PIL import Image
sys.modules['Image'] = Image
2) Run the following two lines in your notebook to be sure that they are correctly pointing to the same directory (if not it's because your PIL old library is messing up with the Pillow library)
from PIL import Image
print(Image.__file__)
import Image
print(Image.__file__)
3) If that's working correctly and both import prints pointing to the same python3 directory then move on.
If not:
3.a) Go to your OS console and to your conda environment (be sure you are working within your desire conda environment) :
conda uninstall PIL
conda uninstall Pillow
conda install Pillow
You should now have successfully installed all the libraries for Pillow and let behind any problems with PIL.
3.b) Now try to execute the code of your jupyer notebook again, now the paths to both the imports should look exactly the same
4) Now, in the OS console/terminal, having your desired conda environment active, run the following commands:
conda install keras
conda install tensorflow
5) Run your jupyter notebook script again, It should be fixed and working now!
If it's still not working, it must be because you have opened a jupyter notebook kernel that's not point to the right environment. Fix that and you will be fine!
If this problem is being seen on an Anaconda env,
use
conda install pillow
and reopen
I ran into a similar issue with keras + tensorflow + miniconda.
I followed this advice from this issue : https://github.com/asataniAIR/Image_DL_Tutorial/issues/4 and did a pip install in conda admin console.
So I enter
pip install --upgrade tensorflow keras numpy pandas sklearn pillow
on anaconda prompt, and add
from sklearn.preprocessing import LabelEncoder
in python code instead
from PIL import Image
Here's what worked for me. Uninstall the conda version of pillow and install the pip version, then restart the kernel of your Jupyter Notebook
conda uninstall --force pillow
pip install pillow
pip install pillow
This did it for me as well.
I am using Jupyter Notebook, and Tensorflow2.0 Keras. To set the context, I got this error when i was trying to use builtin image.load_img() function in Keras. You will have to restart your kernel as well after doing this install.
I encountered the same problem while working on Pycharm. Even after trying various methods on the internet, I could not solve it. When I ran the code on Jupyter notebook, it asked me to install the module, SciPy. I installed it and the code is now working on Pycharm.
I have the same problem good news is it can be easily solvable.
my problem was:
I was using jupyter notebook for my python project which was launched using Anaconda navigator. In the python program I was using the function
image_ = image.load_img(image_path, target_size=(224,224))
then I got this error "raise ImportError('Could not import PIL.Image. ' ImportError: Could not import PIL.Image."
solution worked for me:
in the environment you are using for jupyternotebook firstly uninstall pillow using the command
conda uninstall --force pillow
then install it using the command
pip install pillow
(type these commands in the anaconda prompt)
then close all your notebooks and anaconda navigator, open anaconda navigator with the environment that you have installed before, in that environment launch the jupyter notebook and run the code
it will work
I had the exact same question. And I fixed it by changing my environment variables. Because I had two versions of python in my windows PC.
So I changed the priority, and moved the python 3.x version at the top position.
Then I reinstalled the pillow, and the problem was solved.
if pip and conda installing is not working for you try to:
pip3 install pillow
and then:
from PIL import Image
It should work! Check your python version and which one are you using as default! :)
Using a conda environment run conda install pillow. If you're using Jupyter notebook, don't forget to restart the Kernel.
This just worked for me.
If anyone wondering the above-mentioned process can be implemented using anaconda navigator.
Open the navigator, go to the Environments tab you are currently working and search pillow from the uninstalled tab before the search tab (if it's not installed in the current environment you are working)
Then select pillow and apply. Install then.
After that go to Home tab and launch Spyder.
If your using Anaconda 3, u have to install Pillow in the environment that your working on. just go to the not install section and search for Pillow, then install it to the environment. This way will nail the problem for you.
Install these:
$ pip install pillow -U
$ pip install pathlib -U
It may be a version issue, I had this issue with TensorFlow 3.2.0 and setting pillow to 8.2.0 worked for me somehow along the way of uninstall/reinstall/restart.

Resources