Python 3.5 SFTP file transfer - python

I would like to use paramiko for SFTP file transfer in Python 3.5. I know that paramiko depends on PyCrypto and have read about PyCrypto installation problems in Python 3.5. Although I have seen a number of questions regarding this topic, I have not found a solution to successful SFTP file transfer in Python 3.5.
My first question: is it possible to use Python 3.5 for SFTP file transfer? If so, will paramiko work? If the above will work, why I am I receiving the following errors when attempting to install PyCrypto?
error: [WinError 2] The system canot find the file specified
**Failed building wheel for pycrypto**
My second question: if paramiko will not work with Python 3.5, are there any alternatives or must I revert back to a previous python version for SFTP file transfer?

The solution was to install Python 3.5.1 on my Linux server and then pip install paramiko from there. I'm still not sure why PyCrypto cannot be installed in Python 3.5 for Windows but this was the only solution I was able to find.

You can install PyCrypto binaries for Python 3.5 if you don't have a C++ compiler installed (that pip need to use to compile this library)
Install a PyCrypto binary from this site :
https://github.com/sfbahr/PyCrypto-Wheels
The best way to do it, is:
64bits Python
c:\Python35\Scripts\pip.exe install --use-wheel --no-index --find-links=https://github.com/sfbahr/PyCrypto-Wheels/raw/master/pycrypto-2.6.1-cp35-none-win_amd64.whl pycrypto
32bits Python
c:\Python35\Scripts\pip.exe install --use-wheel --no-index --find-links=https://github.com/sfbahr/PyCrypto-Wheels/raw/master/pycrypto-2.6.1-cp35-none-win32.whl pycrypto
Of course replace c:\Python35\Scripts\pip.exe by your python pip path
To know your python version, run python and look at the architecture displayed between brackets:
C:\Users\utilisateur>python
Python 3.5.1 |Anaconda 4.0.0 (64-bit)| (default, Feb 16 2016, 09:49:46) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Hope this can help.

Related

'import pyodbc' leads to 'No module named pyodbc '

I recently ran pip install pyodbc. Which says it installed pyodbc successfully on the cmd.
However when I do import pyodbc in IDLE I receive an error saying 'No module named pyodbc'.
It seems only two files have been installed when I ran pip install pyodbc.
The two files:
pyodbc-4.0.26.dist-info
pyodbc.cp36-win32.pyd
VERSION of Python:
Python 3.6.3
Complete Error Message:
Error Message
How do I resolve this issue? Any help would be much appreciated, I'm new to python and this is quite frustrating.
The files that installed are fine. *.pyd is compiled library (see https://docs.python.org/3/faq/windows.html#is-a-pyd-file-the-same-as-a-dll).
Issues that may cause this:
IDLE running main python installation and you installed the package in virtual environment
You have several installations of python e.g. python 3.x alongside python 2.x
I think first of all try to run all the steps from the same cmd:
PS C:\Windows\system32> pip install pyodbc
Collecting pyodbc
Using cached https://files.pythonhosted.org/packages/17/00/7115c072d4d01da4feee740cf5d964b4367ba0f9843d334d64ef77fd2baa/pyodbc-4.0.26-cp36-cp36m-win_amd64.whl
Installing collected packages: pyodbc
Successfully installed pyodbc-4.0.26
# now just run python interpreter
PS C:\Windows\system32> python
Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyodbc
# no error
This should work...
And then try to understand if you have several virtualenvs or python instalations.
You can check which python IDLE run, by right click on it's shortcut and "open file location" for example

Python Modules installing properly but dont exist in editors

I want to start with I am new to the python language and am learning on my own. My issue is that I am installing the modules that I'm trying to use. The installs are successful but do not exist when I try to import them. I am using Visual Studio Code, Python 3.6, and Anaconda on Windows 10.
I am trying to use pyttsx3, SpeechRecognition and pocketsphinx.
$pip list
This gives me a very large list but does not contain either of my installed modules.
$python -m pip list
Gives me smaller output with them.
Package Version
----------------- ---------
beautifulsoup4 4.6.0
bs4 0.0.1
certifi 2018.4.16
chardet 3.0.4
click 6.7
gTTS 2.0.0
gTTS-token 1.1.1
idna 2.6
pip 10.0.1
pocketsphinx 0.1.3 #Here
pypiwin32 223
pyttsx 1.1
pyttsx3 2.7 #Here
pywin32 223
requests 2.18.4
setuptools 39.1.0
six 1.11.0
SpeechRecognition 3.8.1 #Here
urllib3 1.22
wheel 0.31.0
I know their installed but when I try to use any of the imports.
$python
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyttsx3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pyttsx3'
I am fine with this being something small on my part due to my lack of knowledge with this language, but I have done a full days worth of research trying to solve this myself.
Edit:
$pip --version
pip 9.0.1 from C:\Users\Keiro\Anaconda3\lib\site-packages (python 3.6)
You have two versions of pip perhaps two different installations of python as well. One with Anaconda and other one by main site.
Stick to one version and if you install in that use that environment in Visual Studio(Or VS Code)
You have installed those in anaconda which the standard installtion of Python wont recognize..
Open Python prompt from Anaconda Navigator >> Choose the environment (Select base for default) >> Open with Terminal [Or Open with Python]
>>python
>>import pyttsx3
In Visual Studio code set the same environment
Ctrl+Shift+P >> Select Python interpreter
Choose the anaconda location.
Volla. Now it should work
I had the same problem and found the answer in an old forum.
Write "pip3" instead of "pip".
So the code is:
pip3 install pyttsx3
(Source: bash: pip: command not found)

How to use Python Dbus bindings in Anaconda

I am trying to install dbus on Anaconda python environment and I am struggling.
Here is the error message I am getting:
e#gateway:~$ python
Python 3.5.4 |Anaconda custom (64-bit)| (default, Oct 13 2017, 11:22:58)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dbus
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/e/anaconda3/lib/python3.5/site-packages/dbus/__init__.py", line 77, in <module>
import dbus.types as types
File "/home/e/anaconda3/lib/python3.5/site-packages/dbus/types.py", line 6, in <module>
from _dbus_bindings import (
ImportError: /home/e/anaconda3/lib/python3.5/site-packages/_dbus_bindings.so: undefined symbol: _Py_ZeroStruct
>>>
Here are some of the outputs I think may be asked:
e#gateway:~$ conda install dbus
Fetching package metadata ...........
Solving package specifications: .
# All requested packages already installed.
# packages in environment at /home/e/anaconda3:
#
dbus 1.10.22 h3b5a359_0
e#gateway:~$ sudo apt-get install libdbus-glib-1-dev libdbus-1-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
libdbus-glib-1-dev is already the newest version (0.106-1).
libdbus-1-dev is already the newest version (1.10.6-1ubuntu3.3).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
e#gateway:~$ sudo apt-get install dbus
Reading package lists... Done
Building dependency tree
Reading state information... Done
dbus is already the newest version (1.10.6-1ubuntu3.3).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
e#gateway:~$ which python
/home/e/anaconda3/bin/python
e#gateway:~$ conda --version
conda 4.3.31
e#gateway:~$ sudo /home/e/anaconda3/bin/python -m pip install dbus-python
The directory '/home/e/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/e/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied: dbus-python in ./anaconda3/lib/python3.5/site-packages
DBus is working fine on the system python, however not working on Anaconda Python.
Python 2.7:
e#gateway:~$ which python
/usr/bin/python
e#gateway:~$ python
Python 2.7.12 (default, Nov 20 2017, 18:23:56)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import dbus
>>>
Python 3.5:
e#gateway:~$ which python3
/usr/bin/python3
e#gateway:~$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dbus
>>>
Can anyone help me? Am I missing something blatantly obvious here?
Thanks in advance.
I had similar issues, there are few cases where dbus and python don't work well out-of-the-box. The consensus appears to be that you need a system-level install (i.e. apt-get) to get dbus to work. I believe the /home/e/anaconda3/lib/python3.5/site-packages/_dbus_bindings.so: undefined symbol: _Py_ZeroStruct error you're seeing is directly related to that.
conda install dbus does not add anything to ~/anaconda3/lib/python3.6/site-packages, but instead appears to install some executables in ~/anaconda3/bin/ like dbus-run-session, dbus-daemon, etc. This makes some sense when you analyze the contents of the dbus tarball https://anaconda.org/conda-forge/dbus, as it's all C files and executables. I'm not sure it's supposed to be the dbus python module, but I could be wrong.
EDIT:
I searched the conda repositories and found a few individuals that uploaded a version of dbus-python, presumably that they compiled and installed. I tried this one out in a py3.6 conda environment via:
conda install -c scottwales dbus-python
I was then able to import dbus. This is a hacky approach and should not be used in production, I'd recommend listening to
Carlos Cordoba's post below. But if you need a solution now, search through some user conda packages or try to compile the library yourself.
Can anyone help me? Am I missing something blatantly obvious here?
Yes, you are. There's one thing people still don't understand about conda: conda is not a pip replacement. It is a general package manager, in the same vein as apt-get, yum, brew, emerge, etc, but cross-platform and based on Python.
In this case, that means that conda install dbus does not install the Python Dbus bindings, as you would expect with pip . It installs the Dbus C package itself, which is needed by Qt 5 (again, the C++ library, not the Python bindings to it).
Unfortunately, there are no Conda packages for dbus-python. To make matters worse, it seems there's no easy way to create packages for it, as pointed out here.
Finally, you said
Here is the error message I am getting
The (most probable) cause of that error is because you added your system Python dist-packages path to the PYTHONPATH of Anaconda or because you blindly copied the dbus module from system Python to Anaconda. Please don't do that ever again. System Python and Anaconda packages are compiled with different compilers and under different conditions. So mixing them is the cause of incomprehensible errors, just like the one you reported.

How to install pycurl on a win32 machine without compiling

Please bear with me as I am completely new to programming/python, etc.
I am attempting to install the pycurl module on my local win32 machine. I do not know anything about compiling, and I have attempted to install the module through an msi installer located here:
http://pycurl.sourceforge.net/download/
and I am using the pycurl-7.19.5.win32-py3.4.msi download, with Python 3.4.
I have downloaded it, and when I attempt to run a python query using the command prompt, I receive the error:
ImportError: No module named 'pycurl'
When I run the script without importing pycurl, it runs fine, so I know I have python installed successfully.
What am I doing wrong? I don't want to resort to compiling as that is going in completely foreign territories for me. I'd like to learn how to install modules into python for future purposes as well.
Try installing pycurl from this site, where all modules are as Windows binaries. Installing it and then trying to import pycurl works fine for me (you have to download appropiate .whl for your Python version & platform, then run):
..\Downloads>pip install pycurl-7.19.5.3-cp35-none-win32.whl
Installing collected packages: pycurl
Successfully installed pycurl-7.19.5.3
..\Downloads>python
Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:16:59) [MSC v.1900 32 bit (Intel)] on win32
>>> import pycurl
>>> pycurl
<module 'pycurl' from 'C:\\Program Files (x86)\\Python 3.5\\lib\\site-packages\\pycurl.cp35-win32.pyd'>
The problem you describe may happen when you have multiple versions of Python installed without using virtualenv.
Use pip instead:
pip install pycurl
Edit 2020-12-11:
Pycurl no longer builds binaries. The last binaries available are for Python 3.4 or 3.5.
If you're still using Python 3.4/3.5, and you don't want to/can't build from source, you can install the last available official binary builds from pip using:
pip3 install --only-binary :all: pycurl
WARNING: the latest binary build may be behind the latest source version and therefore have security bugs.

should I re-install python again for zlib module? [duplicate]

This question already has answers here:
Installing distribute in Python 3.3 Ubuntu
(2 answers)
Closed 9 years ago.
When installing distribute-0.6.49 with python3.3.2 in Ubuntu system, error encountered
....blablabla followed by...
"Compression requires the (missing) zlib module")
RuntimeError: Compression requires the (missing) zlib module
I have checked previous solutions that I need to install zlib package, but Should I re install my python again before that? can't I install zlib over it?
If re-installing of python needed, Where can I find python 3.3 with zlib already therein so that i can install python as usual?
To compile Python with zlib support, you need to install the zlib1g-dev package so that Python can find the headers.
You'd need to re-install your source-compiled Python to take this along.
If you are running ubuntu then it is usually recomended that you use the package from the package manager. You can get python 3 - currently 3.3.1 with either sudo apt-get install python3 if I recall correctly or by using the software centre.
I am reasonably sure that the default distribution includes zlib.
Python 3.3.1 (default, Apr 17 2013, 22:30:32)
[GCC 4.7.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import zlib
>>> exit()

Categories