Python from: can't read /var/mail/ - python

I want to use PikePDF
Apparently I have it already installed?
pip install pikepdf
Requirement already satisfied: pikepdf in ./.pyenv/versions/3.9.2/lib/python3.9/site-packages (6.2.9)
Requirement already satisfied: Pillow>=9.0 in ./.pyenv/versions/3.9.2/lib/python3.9/site-packages (from pikepdf) (9.4.0)
Requirement already satisfied: deprecation in ./.pyenv/versions/3.9.2/lib/python3.9/site-packages (from pikepdf) (2.1.0)
Requirement already satisfied: packaging in ./.pyenv/versions/3.9.2/lib/python3.9/site-packages (from pikepdf) (23.0)
Requirement already satisfied: lxml>=4.8 in ./.pyenv/versions/3.9.2/lib/python3.9/site-packages (from pikepdf) (4.9.2)
I guess I need to ad to PATH? I am a complete newbie on this..
My .zshrc
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/shims:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
fi
I tried to run the code in Python:
from pikepdf import Pdf
new_pdf = Pdf.new()
with Pdf.open('in.pdf') as pdf:
pdf.save('Pyout.pdf')
from: can't read /var/mail/pikepdf
zsh: missing end of string
(*) update: as Charles Duffy pointed out, I did not enter in python >>> and was still in ZSH!! 😬
Last login: Thu Feb 2 21:18:08 on ttys002
setopt interactivecomments
xxx#MacBook-Air-di-xxx ~ % setopt interactivecomments
xxx#MacBook-Air-di-xxx ~ % python
Python 3.9.2 (default, Jan 30 2023, 11:04:57)
[Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from pikepdf import Pdf
>>> new_pdf = Pdf.new()
>>> with Pdf.open('in.pdf') as pdf:
... pdf.save('Pyout.pdf')
...
>>>

Related

Tosca parser ImportError: "No modules named". The modules already installed in dist-packages success

I have gone through similar questions but I still cant resolve the problem
I have install the package and success but when I run my script it will always return no module name error.
I suspect something todo with the python path where the module may not in python path
This is my code
from toscaparser.tosca_template import ToscaTemplate
path_to_yaml_file = 'cvx.yaml'
template = ToscaTemplate(path_to_yaml_file)
print(template.inputs)
error
from tosca_parser import ToscaTemplate
ModuleNotFoundError: No module named 'tosca_parser'
My python
python
Python 3.8.10 (default, Nov 14 2022, 12:59:47)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload',
'/home/cube1/.local/lib/python3.8/site-packages', '/usr/local/lib/python3.8/dist-
packages', '/usr/local/lib/python3.8/dist-packages/pytosca-0.2.1-py3.8.egg',
'/usr/lib/python3/dist-packages']
Package is success install using pip
Requirement already satisfied: attrs>=16.3.0 in /usr/lib/python3/dist-packages (from
cmd2>=1.0.0->cliff!=2.9.0,>=2.8.0->tosca-parser) (19.3.0)
Pip version
pip --version
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
Run echo $PYTHONPATH only return blank line
I did run the script in tosca-parser dir and it work. Thus, something is not right with tosca parser module and python path outside the dir. Need some help and advise how can I fix this. Thank you

pip3, python does nothing on Windows cmd

Yes, I already read that question but it didn't help me.
C:\Users\*\Documents\git-workspace\redditCountdownGui>"C:\Program Files\WPy64-3741\python-3.7.4.amd64\Scripts\pyinstaller.exe"
C:\Users\*\Documents\git-workspace\redditCountdownGui>
I tried using this method:
C:\Users\*\Documents\git-workspace\redditCountdownGui>"C:\Program Files\WPy64-3741\python-3.7.4.amd64\python.exe" -m pyinstaller
C:\Program Files\WPy64-3741\python-3.7.4.amd64\python.exe: No module named pyinstaller
C:\Users\*\Documents\git-workspace\redditCountdownGui>
I can't get it to work. It's also not working for pip:
C:\Users\*\Documents\git-workspace\redditCountdownGui>"C:\Program Files\WPy64-3741\python-3.7.4.amd64\Scripts\pip.exe"
C:\Users\*\Documents\git-workspace\redditCountdownGui>"C:\Program Files\WPy64-3741\python-3.7.4.amd64\Scripts\pip3.exe"
C:\Users\*\Documents\git-workspace\redditCountdownGui>
I also tried adding to PATH but then it's the same - no output at all.
Can anyone help me?
When using WinPython, you need to start WinPython Command Prompt to get all Paths set correctly. Within that shell, you can use pip as usual:
D:\WPy64-3740\scripts>python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable
'D:\\WPy64-3740\\python-3.7.4.amd64\\python.exe'
>>> exit()
D:\WPy64-3740\scripts>python -m pip install requests
Requirement already satisfied: requests in d:\wpy64-3740\python-3.7.4.amd64\lib\site-packages (2.22.0)
Requirement already satisfied: certifi in d:\wpy64-3740\python-3.7.4.amd64\lib\site-packages (from requests) (2019.6.16)
Requirement already satisfied: urllib3 in d:\wpy64-3740\python-3.7.4.amd64\lib\site-packages (from requests) (1.25.3)
Requirement already satisfied: chardet in d:\wpy64-3740\python-3.7.4.amd64\lib\site-packages (from requests) (3.0.4)
Requirement already satisfied: idna in d:\wpy64-3740\python-3.7.4.amd64\lib\site-packages (from requests) (2.8)
D:\WPy64-3740\scripts>
I know it's a lazy answer, but this is Windoze. You should simply uninstall and reinstall Python.
During the install, the python executable should get added to the paths correctly ...although (depending on installer) you may need to specifically select a checkbox to add it to the system paths. It should also install pip, although (again) you may need to specifically select that in a checkbox during install.
After (proper) installation, you should be able to open a cmd window, and simply type python and be dropped into the Python working environment. You should also be able to just type pip and find the working copy of pip.
If you can't do this, your Windows environment has gotten screwed up :/
Please note, if you have more than one version of Python installed, you may need to type python3 / pip3 to access the correct version.
The error message No module named pyinstaller is because the Python can't find your site-packages. This is also a result of your paths being screwed up when you're calling python.
Try running the command python -m site to see where your site-packages is installed, ensure it is in your paths, and ensure that the module in question is installed there.
Different versions of Python have their own paths for site-packages. So installing a module for Python 2.7 does not install it for Python 3.x

python module not found after pip installation

Tried to install PythonQwt using pip, and also the recommended method below:
$ python3 -m pip install PythonQwt
Requirement already satisfied: PythonQwt in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (0.5.5)
Requirement already satisfied: NumPy>=1.3 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from PythonQwt) (1.17.2)
But I'm still getting this
$ python3
Python 3.7.4 (v3.7.4:e09359112e, Jul 8 2019, 14:54:52)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import PythonQwt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'PythonQwt'
already looked up different answers on stack overflow and tried them
Though the package name is PythonQwt, you import it as just qwt. One example from the official documentation is:
from qwt import tests
tests.run()

dbus not working with python3 on a virtual environment?

I set up a virtual environment named "ComputerVision" with virtualwrapper, virtualen and pthon3.
Everything works fine except of importing dbus in my python script.
I want to use python3 but as you can see:
-dbus can be importet with python2 not python3
-cv2 can be importet with python3 not python 2
(ComputerVision) pi#raspberrypi:/ $ python3
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dbus
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'dbus'
>>> import cv2
>>> exit()
(ComputerVision) pi#raspberrypi:/ $ python2
Python 2.7.13 (default, Sep 26 2018, 18:42:22)
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import dbus
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cv2
>>> exit()
(ComputerVision) pi#raspberrypi:/ $ pip install dbus-python3
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting dbus-python3
Could not find a version that satisfies the requirement dbus-python3 (from versions: )
No matching distribution found for dbus-python3
(ComputerVision) pi#raspberrypi:/ $ pip install python3-dbus
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting python3-dbus
Could not find a version that satisfies the requirement python3-dbus (from versions: )
No matching distribution found for python3-dbus
(ComputerVision) pi#raspberrypi:/ $ pip install python-dbus
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting python-dbus
Could not find a version that satisfies the requirement python-dbus (from versions: )
No matching distribution found for python-dbus
(ComputerVision) pi#raspberrypi:/ $
How can I fix it, to be able to import dbus to my python3 script??
Thank you in advance.
You need to install dbus-python library for Python3:
pip3 install dbus-python

Why is Python 3 looking in my Python 2.7 package directory for packages?

OS (Linux): Ubuntu 14.04.4 LTS (Trusty Tahr)
For some reason, my Python 3.5.2 is looking into the Python 2.7 packages directory instead of its own:
] python3 -m ensurepip
Ignoring indexes: https://pypi.python.org/simple
Requirement already satisfied (use --upgrade to upgrade):
setuptools in /usr/local/lib/python3.5/site-packages
Requirement already satisfied (use --upgrade to upgrade):
pip in /usr/local/lib/python2.7/dist-packages
More details:
] python3
Python 3.5.2 (default, Jul 29 2016, 09:41:38)
[GCC 6.1.1 20160511] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import site; site.getsitepackages()
['/usr/local/lib/python3.5/site-packages']
>>>
^^^-- That seems correct and does not mention anything about the 2.7 packages directory.
It looks like it should only be looking in /usr/local/lib/python3.5/site-packages, but for some reason, it is also looking in /usr/local/lib/python2.7/dist-packages where it has no business in looking.
For example, look at what happens when I try to install psycopg2 as a Python 3 module:
] python3 -m pip install psycopg2
Requirement already satisfied (use --upgrade to upgrade):
psycopg2 in /usr/local/lib/python2.7/dist-packages
It is finding it as an installed package in the 2.7 distribution and failing to install its Python 3 version in /usr/local/lib/python3.5/site-packages.
To add even more confusion into the mix, I try going straight for pip 3, but to no avail:
] pip3 install psycopg2
Requirement already satisfied (use --upgrade to upgrade):
psycopg2 in /usr/local/lib/python2.7/dist-packages
] cat `which pip3`
#!/usr/local/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from pip import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
Update: PYTHONPATH was set to /usr/local/lib/python2.7/dist-packages. This was the cause of the issue above. Credit goes to user be_good_do_good for helping me figure out which screw to turn to get things to work as they should.
PYTHONPATH might have been set to 2.7 distribution packages, which might be causing this.

Categories