tftpy package sytax errors on import - python

I've just installed the package tftpy version 0.6.2 when I import it I get a syntax error with the line:
running the code:
import tftpy
I get the error:
raise ImportError, "Requires at least Python 2.3"
SyntaxError: Invalid syntax
I have version 3.6.3 installed.
import sys
print(sys.version_info)
gives me the out put major=3, minor=6, micro=3.
However the line of code that raises the syntax error is the last line in the code below:
import sys
required_version = (2, 3)
if sys.version_info < required_version:
raise ImportError, "Requires at least Python 2.3"
I don't think the issue is with my version number I think it doesn't like the syntax used to raise the ImportError exception.
Any help would be greatly received.

I found the error in my case.
When you run a tftpy server, you need to run it as sudo, therefor you need to install tftpy as sudo also.
In my case:
$ sudo pip3 install tftpy
$ sudo python3 tftpy-program.py
Also remember that if you use python3, f.eks, you need to install the package with pip3, and not jsut pip. Hope it helps.

Related

How to fix pip that it points to the correct python?

So i just installed python3.10 on Ubuntu 20.04 and made it default. After that tried to run a program which imports pygame and get an Error `
" ModuleNotFoundError: No module named 'pygame.base'
After a little bit of research the solution might be
pip3 uninstall pygame
and to reinstall it, but then i get that error
ImportError: cannot import name 'html5lib' from 'pip._vendor' (/usr/lib/python3/dist-packages/pip/_vendor/init.py)
`which pip3 and which python3 give me 2 different directionaries
Now my question: How do i get them in the same that the pip points at the correct python ?
`
the answer exist in this stack overflow url :ImportError: cannot import name 'html5lib' from 'pip._vendor' (/usr/lib/python3/dist-packages/pip/_vendor/__init__.py)
and also you can use something like that for use pip with correct python version, for instanse:
python3 -m pip install <package_name_you_want>

ModuleNotFoundError: No module named 'yaml' error

I have a centos7 machine with python-2.7.5 installed as a default python.
For my work, I need 3.x version of python on the same machine, so I have installed python-3.6.8 and created a soft link where /usr/bin/python point to /usr/bin/python3 with following command:
sudo ln -fs /usr/bin/python3 /usr/bin/python
Now, for a sample python script, let's say: test.py, I am getting ModuleNotFoundError: No module named 'yaml' error when I am trying to import yaml in it.
test.py script is as below:
#!/usr/bin/python3
"""
Sample python script to import yaml.
"""
import yaml
print("Hello! Could you please help me resolve this?")
And the error is as below:
[cloud-user#xx.xx.xx.xx]$python test.py
Traceback (most recent call last):
File "test.py", line 6, in <module>
import yaml
ModuleNotFoundError: No module named 'yaml'
I saw a couple of queries raised on stackoverflow and on github, like this, this and this, but do not see any response that has resolved this issue.
As suggested on the links above, I have installed pyyaml using below command:
sudo python3 -m pip install pyyaml and sudo pip3 install pyyaml but I am still continue to get ModuleNotFoundError error.
Could anyone please help me resolve this issue?
Thanks in advance,
Akshat Sharma
Such issues occur when there are multiple distribution of python installed in your system.
Just run: pip3 list command and see whether you are able to see the package in the list. If not, you are not installing the PyYaml package at the correct location.
PS: also sometimes for normal user python is at different location and for sudo user, it is at different location. Check running the command without giving sudo.

Installing numpy, cython, cpython for Python 2.7.12

I have been trying to install numpy for Python 2.7.12 on a ubuntu 16.04 machine, but am not sure I am doing the right thing.
I issued the command
python setup.py install
and received the following error message:
ImportError: No module named Cython.Compiler.Main
So I have also been trying to install the cython package and received another error message:
/Cython-0.28.1/Cython/Plex/Scanners.c:19:20: fatal error: Python.h: No such file or directory
I thought this problem required me to install cpython. Trying to install this resulted in the following error message:
Traceback (most recent call last):
File "setup.py", line 4, in <module>
import sys, os, importlib.machinery, re, optparse
ImportError: No module named machinery
I am somewhat stumped about how to continue. Am I on the right path? Is there a different way I could try (the computer in question cannot connect to the internet)?
You can check if pip is install thanks to the command which pip,
in my case :
$ which pip
/home/usr1/anaconda3/bin/pip
If pip is not install install it : instruction here
then you should be able to use it such as :
pip install numpy
an alternative is to use : conda install
In the terminal use:
pip install numpy
If you get any error like 'permission denied', try:
sudo pip install numpy

Cannot Import Python Packages on Linux

I ran this in the terminal to install all the packages for a machine learning project.
sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose
It says the packages are already their newest version. When I run import numpy from the interpreter prompt, it just runs without a flaw.
But when I say numpy.version it says "module 'scipy.version' from '/usr/lib/python2.7/dist-packages/scipy/version.pyc'" without showing the version name. Also, the package import fails when I try a script.
On further experimentation, I figured a script as simple as
# Check python
print('Hello world')
is giving this error from a .py file,
./Script.py: line 2: syntax error near unexpected token `'Hello world''
./Script.py: line 2: `print('Hello world')'
Note that the script and version.version commands run fine from the terminal interpreter prompt.
Is something wrong very deep down?
Python version 2.7.12.
In order to get to know the version in python,
import numpy
print numpy.__version__
numpy.version gives the path.
If you want to check the version of numpy, try this:
import numpy
numpy.version.version
As for the following question, please post more information.

ImportError: No module named pynotify. While the module is installed

So this error keeps coming back.
Everytime I try to tun the script it returns saying:
Traceback (most recent call last):
File "cli.py", line 11, in <module>
import pynotify
ImportError: No module named pynotify
The strange thing is, I just installed this plugin.
I also restarted command prompt already, even the computer.
But nothing, if anyone could help me out here that'd be great!
Try this:
pip install py-notify
It worked for me.
You are most likely looking for pyinotify not pynotify. That should fix your ImportError.
Here is the solution for Ubuntu.
First install python-notify: sudo apt-get install python-notify
After that you may need to add the right paths:
import sys
sys.path.append('/usr/lib/python2.7/dist-packages/gtk-2.0')
sys.path.append('/usr/lib/python2.7/dist-packages/')
Finally: import pynotify
first check your pipversion and your python running version
pip --version, python --version
if the pip is from python3's packages. and you python environment is running at python2.x. so abandon using your pip to install any notify , you just install python-notify
If what you install is py-notify (http://home.gna.org/py-notify/), it should be:
import notify
Check whether you were using the corresponding pip version for your version of Python. For example, if you have Python2 and Python3 installed, you may have installed pynotify for Python2, and attempting to import it from Python3, which will result in the package not being found.
Try running
pip --version
Assuming pip install is how you installed the package as well as
python --version
to ensure the version numbers are similar.
Import package 'notify' instead of 'pynotify'
import notify
This error is because, you had run the Python file (mitmf.py) with python2. But you have installed pyinotify in python3-pip. So it will only run in pip2.To install it follow the link... https://linuxize.com/post/how-to-install-pip-on-ubuntu-20.04/

Categories