ImportError exception encountered while trying to use Fabric - python

I am using Ubuntu and virtualenv, and I am having this recurring problem, while attempting to use Fabric to create a deployment script. Fabric depends on paramiko, which depends on PyCrypto.
Each time I try to use Fabric, or PyCrypto directly, I get this error:
ImportError: cannot import name Random
I have tried reinstalling with pip install -U PyCrypto. I have also tried installing the python-crypto and python-crypto-dbg packages with Aptitude, to no avail. I still get the same error. Anyone have any ideas that might help me solve this problem? Thanks in advance!

It's possible that there's a file name collision in your the directory from which you're running Fabric. Do you have a file called Crypto.py in your project?
Can you get Crypto.Random to import from outside of your project directory? (but still using your virtualenv. Ipython is a big help here.)

I've had the same trouble in the past using Ubuntu. I no longer have a Ubuntu install available, but on my old 10.04 box, the file Random in the Crypto directory was missing. Make sure it exists, if it doesn't, that's the problem.

Related

How do I fix this python converting file into an app - still have not found a solution

This question is not a duplicate of this question, because I am trying to create an app.
I am currently following this tutorial, but when I try to run my app,
my command prompt prints out this error:
Why does this error happen and how can I solve it? I read through all the answers to the linked question, but none of them are pertinent to my problem.
Please anyone help me, I still haven't found a working solution; I am getting desperate!!!
Edit: I can't just install and uninstall pynput? Idk why it doesn't work because shouldn't pynput come with idle?
Version: 3.74 python idle, most updated version of pyinstaller
The following might help you if you haven't tried them already:
Update pip from the command line
Unistall pyinstaller
Re-install pyinstaller and try it again
If the above does not work, try running the following command in the command line. Make sure there are some print statements in your code to see if it works.
python monitoring_culmination_product.py
If you got a message saying "python is not recognised as an internal or external command" then python might have not been added as an environment path.Try this to fix the issue.
You could always re-install python if things get difficult.(make sure you install the appropriate version 32-64bit)
If the command though executed without a problem. Try to use pyinstaller on another file to see if the problem has to make sure the problem has to do with pyinstaller.
From a personal experience, pyinstaller can be unreliable at times so I put the following line in my projects just to make sure. It might help you too.
import pkg_resources.py2_warn
Disclaimer: Although it is not specified I assume that you are using Windows
You could try to use conda create to get an environment containing all the need dependencies (numpy, etc) and then use pyinstaller as explained in this discussion.
Please fall back to 1.6.8 version of pynput. pip install pynput==1.6.8
Ref : https://stackoverflow.com/a/63721929/14759065

How can I make this script run

I found this script (tutorial) on GitHub (https://github.com/amyoshino/Dash_Tutorial_Series/blob/master/ex4.py) and I am trying to run in my local machine.
Unfortunately I am having and Error
I would really appreciate if anyone can help me to run this script.
Perhaps this is something easy but I am new in coding.
Thank you!
You probably just need to pip install the dash-core-components library!
Take a look at the Dash Installation documentation. It currently recommends running these commands:
pip install dash==0.38.0 # The core dash backend
pip install dash-html-components==0.13.5 # HTML components
pip install dash-core-components==0.43.1 # Supercharged components
pip install dash-table==3.5.0 # Interactive DataTable component (new!)
pip install dash-daq==0.1.0 # DAQ components (newly open-sourced!)
For more info on using pip to install Python packages, see: Installing Packages.
If you have run those commands, and Flask still throws that error, you may be having a path/environment issue, and should provide more info in your question about your Python setup.
Also, just to give you a sense of how to interpret this error message:
It's often easiest to start at the bottom and work your way up.
Here, the bottommost message is a FileNotFound error.
The program is looking for the file in your Python37/lib/site-packages folder. That tells you it's looking for a Python package. That is the directory to which Python packages get installed when you use a tool like pip.

How to compile TeX file from Python

I'm trying to create a pdf file inside a python/django project. I'm using PyLatex, which helps, but it's generate_pdf method breaks when it calls pdflatex. I keep getting this error:
FileNotFoundError: [Errno 2] No such file or directory: 'pdflatex'
I tried everything - os.system() ... subprocess. Any way I try, it can't find pdflatex. I'm running on Windows, but I need to be able to to do this within the web-app anyway.
Thanks for any help!
You just need to install pdflatex (and you will need to install on your server when you release your web-app). Instructions for installing on windows can be found in the top answer here.
Do you have "pdflatex" installed? As per this question, you may have to install "MiKTeX" and point os.system() at C:\Program Files\MiKTeX <MikTeX version>\miktex\bin to make it work.
Hope that helps.
Do you have texlive installed? If yes, then the issue is with the system path variable. If not already added, add it to the system path.
#
Updated answer:
I took the time and decided to replicate your issue. I too use windows.
I copied the basic example from Pylatex and tested it on my machine, I was able to replicate the same error as you despite having TexLive installed. To solve it I did the following steps:
Installed MikTex (I believe you have it installed).
Tried running it again but failed with the error missing package latexmk.
Using MikTex package manager, I installed the latexmk package.
Tried running but still failed, error missing perl.exe command.
I had to install perl to my windows, use the following links -- https://learn.perl.org/installing/windows.html
When I tried again, it compiled successfully.
The issue was not having the package latexmk for MikTex and perl.exe of which you should have posted as part of the error logs. Try that and let me know if successful.

How to install mesos.native python module in Mac OS and Ubuntu

I would like to write and run a Mesos framework with Python, so I need mesos.native module.
On Ubuntu:
I can build mesos from source code. I tried to easy_install all the generated egg files but none of them made it possible for Python to import mesos.native.
I also tried to download the egg from http://downloads.mesosphere.io/master/ubuntu/14.04/mesos-0.20.1-py2.7-linux-x86_64.egg and easy_install it, which didn't work as well.
On Max OS:
Got some problem building the mesos source code because of the issue. So I am wondering whether there is an easy way to install the Python module without building the source code.
BTW, why don't they make the mesos.native pip-installable like mesos.interface?
Problem solved: https://github.com/RobinDong/mesos-python-examples/blob/master/calculate_pi/pi_run
I just need to set PYTHONPATH as that in the file and run python. Mesos.native can be successfully loaded.

ImportError: No module named twisted.persisted.styles

From IDLE, I tried to run a script with a newly installed scrapy 1.0.3.
I'm using a script from a friend whom it worked for (but on Windows, I'm on a Mac).
From the import of scrapy on the first line, I get this error when running the program:
ImportError: No module named twisted.persisted.styles
The whole script, if it's helpful, points to this:
Traceback (most recent call last):
File "/Users/eliasfong/tutorial/tutorial/spiders/medspider.py", line 1, in <module>
import scrapy
File "/Library/Python/2.7/site-packages/scrapy/__init__.py", line 27, in <module>
from . import _monkeypatches
File "/Library/Python/2.7/site-packages/scrapy/_monkeypatches.py", line 20, in <module>
import twisted.persisted.styles # NOQA
ImportError: No module named twisted.persisted.styles
Any suggestions on how to tackle this problem?
Just try to force the update of twisted :
pip install twisted --upgrade
That works for me with python3.4 and Scrapy==1.1.0rc1
Either twisted is installed on your mac (I highly doubt it since it's not a standard library) and for whatever reason the IDE (i'm assuming that's what you mean since you typed "idle") or the terminal you are in doesn't have your updated environment variables, meaning it doesn't understand where your default python libraries are (again I highly doubt it), or you simple do not have twisted installed on your mac. If it's not installed you have a couple of options:
The easiest way to install a python package is through pip.
If that not an option you can try homebrew which is another package manager for macs. It offers an easy way to install packages correctly.
If that still is not an option for you or you simply don't want to attempt that you can download twisted directly from here (the .bz2 since you're on a mac), click on it and it should unzip it for you. Then just run setup.py and it should install it in the correct location on your mac.
If that still doesn't work and you have decent knowledge of unix. Use the "locate" command on the terminal and find out where your dist-packages directory is and put the source for twisted in there directly and then attempt to import twisted in your IDE or in the python interpreter to verify that it is installed.
note: If you're still having problems after it is installed trying restarting your IDE or messing with some setting to make sure your IDE has the right environment and python path. Hope that helps!
It could be related to having installed Python without bzip2. I had the same error and this helped me, see the accepted answer here:
Installing Twisted through pip broken on one server
Had this exact thing on FreeBSD. Solution (as root/sudo):
chmod -R go+rX /usr/local/lib/python2.7/site-packages
Some directory permissions weren't set up right on install.

Categories