How to resolve Python import module? - python

I'm on Ubuntu 20.4. When I execute a Python script, I get the following error and sys.path.
I installed the packages with pip3 and they are located in
/usr/local/lib/python3.8/dist-packages
When I look at the installed packages for python3 and python3.8 interpreter, I see "binance" package installed and recognized.
I tried to set PYTHONPATH to point to my project folder, but that didn't help either.
echo $PYTHONPATH --> /algos_python

You have installed binance from PYPI but you are not using it. You are using python-binance and you need to install it. (Using python3 -m pip install python-binance) and then run your code again. See this for more info on this.

Try these:
python3 -m pip install python-binance
If you are calling your file binance.py (Or have a file/folder named that in your directory), and then trying to import from binance.client, python will look in your binance.py file instead of the library. So try renaming your local file.

Related

"No module named pefile" even though I have installed pefile

I have Python 2.7 and Python 3.8 on the same computer
I am trying to get this to work: https://github.com/countercept/python-exe-unpacker
The requirements are:
pefile==2017.9.3
unpy2exe==0.3
uncompyle6==2.11.5
xdis==3.5.5
pycrypto==2.6.1
configparser==3.5.0
And I guess the other stuff is installed correctly (not sure). But when I try to currently run this thing with python python_exe_unpack.py -i [programname.exe]
I get the error:
C:\Python27\python.exe: No module named pefile
I've run both of these commands:
py -m pip install pefile==2017.9.3
py -m pip install pefile==2019.4.18
and the problem persists.
Any idea what might be going wrong?
You should use pip freeze to obtain the list of installed packages. Probably your py and python executables aren't the same, try py python_exe_unpack.py -i [programname.exe]. Also check which paths you using to obtain that package:
import sys
print(sys.path)
You can add extra paths through PYTHONPATH environment variable or just sys.path.append("/path/to/folder") with path where is you're installed pefile.

How to move all modules to new version of Python (from 3.6 to 3.7)

I just upgraded to python 3.7 and I realized that all my modules stuck with the previous version. Even Django is not recognised anymore. How can I do to transfer everything to the new version? I am a little lost right now, don't even know where the new version has been installed.
Edit:
When I do $ which python3.6 the terminal tells me it doesn't exist, but I have a python3.6 directory in /usr/local/lib/, where all modules are installed.
In the same directory /usr/local/lib/ I also have a python3.7 directory with some modules installed but many are missing. However when I search for the file python3.7 in my finder it doesn't appear. when I do $ which python3.7 the path is /usr/local/bin so not the same path as the directory.
Anyone sees what happened and knows how I can transfer all modules to python3.7?
Even if the old python version has been removed, it is possible to use the pip of the current python version with the --path option to list all the modules installed in the previous version.
For example, migrating all my user installed python modules from 3.7 to 3.8
pip freeze --path ~/.local/lib/python3.7/site-packages > requirements.txt
pip install --user -r requirements.txt
Incidentally, I always use pip install with --user and leave the system wide installations to the package manager of my linux distro.
It is safer to re-install all packages due to possible compatibility issues:
pip3.6 list | awk '{print $1}' | xargs -I{} pip3.7 install {}
in older version of Python --run the command
pip freeze > requirements.txt
download and install newer version on python.. change the PATH variable to the new version
and run the command
pip install -r requirements.txt
I'm not sure about all modules...but if you want to install a module specifically in python3.7, try this:
python3.7 -m pip install *module_name*
In some cases, we don't have the opportunity to pip freeze in old version--because I've already updated and old version have been purged! There are some measures I've taken to recover some of the packages but I'm NOT sure every package would work with this fix.(e.g. the packages built with wheels)
mv /your/path/to/python3.{6,7}/site-packages/
If the case is packages installed outside venv (in /usr/local/ or ~/.local), reinstall pip with get-pip.py, just to be safe.
If you are recovering a virtualenv. Activate your virtualenv and use my script
Most of your packages should work by now. If anything malfunctions, pip reinstall would works. If you still want it 100% works, pip freeze now.😉
I have an alternative
(Not sure if works outside Windows 10)
I'm currently migrating from 3.7 to 3.8 and the way I found to re-install my previous libraries was by using a script I had that updates all packages via pip install. (Assuming you installed your new Python version as your main version) This checks for all the packages I had and updates/install them in the new Python version.
Note: I prefer to run the script from the command line
Use the file explorer to go to the folder where you have the script;
Click on the path box, write "cmd" and press enter to open a command line from the folder where you are;
Write "python name_of_your_script.py" and press enter to run the command.
The script (adapted from this solution):
import pkg_resources
from subprocess import call
packages = [dist.project_name for dist in pkg_resources.working_set]
[call("pip install " + name + " --upgrade") for name in packages]
I faced a similar problem, now that I upgraded from python 3.7 to python 3.8 (new)
I installed Python 3.8, but the system kept the python37 subfolder with the already installed packages(...\Python37-32\Lib\site-packages) even with the Pyhton38 subfolder created, with the new python.exe.
Usually, it's possible to keep on using the old libraries on your new Python version, because the existent libraries installation folder are already registered in your local computer system path (*).
Even though, I've had problems to use some libraries (some worked in Jupyter Notebook but not in Spyder). I tried the alternatives others proposed to migrate libraries but it did not worked (maybe I did not
So I used brutal force solution.. Not elegant at all, but it worked:
remove the OLD python version folders from the system path or even remove the folder itself for good..
Folders: C:\Users\USERNAME\AppData\Roaming\Python\Python37
C:\Users\USERNAME\AppData\Local\Programs\Python\Python37
Reinstall the packages you need, preferably via Anaconda prompt.
python -mpip install library_name
OR
pip install --user --force-reinstall package_name
OR
pip install --user --force-reinstall package_name == specify_package_version
The libraries will be installed at c:\users\USERNAME\anaconda3\lib\site-packages and recognized by your new python version.
(*) to add the folder to the PATH: System properties --> environment variables --> click "Path"--> edit --> add folder name)

pyInstaller: ImportError: No module named 'praw'

I wanted to pack my script using pyInstaller. I run pyinstaller file.py -F, file is created successfully, but when running I get ImportError: No module named 'praw'. So I created new file containing only import praw and run pyinstaller file.py -F --hidden-import=praw but still get the same error when running.
I was unable to find anything similar, most issues were solved by using --hidden-import.
Any ideas on how it can be solved?
EDIT:
praw is installed inside virtual environment and running the script directly works as expected.
Seem pyinstaller run outside the virtualenv.
Try switch to your virtualenv and run:
python -m PyInstaller -F file.py
I'll recommend to look at pyenv or virtualenv. Activate these env's and install the praw module here. This should work.
This command might help you out. It installs the Praw module for you. Make sure you have pip installed!
pip install praw
I found a way to solve the issue:
When using Python2.7, or starting the shell like python2, we need to do
python2 -m pip install --user praw
to make sure they are linked during installation.
Same idea for python3 shell.

Why am I getting ImportError: No module named pip ' right after installing pip?

I have installed pip and ez setup. I also checked the system path and I can see the module in the folder structure. Still when i try to run pip command, I get an Import error saying no module named pip. I am running 32bit python on a windows7 machine
Just be sure that you have include python to windows PATH variable, then run python -m ensurepip
After running get_pip.py with python embed you have to modify your pythonXX._pth file. Add Lib\site-packages, to get something like this:
pythonXX.zip
.
Lib\site-packages
# Uncomment to run site.main() automatically
#import site
If you don't you will get this error:
ModuleNotFoundError: No module named 'pip'
or
python-3.8.2-embed-amd64\python.exe: No module named pip
λ pip
Traceback (most recent call last):
File "runpy.py", line 193, in _run_module_as_main
File "runpy.py", line 86, in _run_code
File "python-3.8.2-embed-amd64\Scripts\pip.exe\__main__.py", line 4, in <module>
ModuleNotFoundError: No module named 'pip'
λ python -m pip
python-3.8.2-embed-amd64\python.exe: No module named pip
This issue occurs with me while I was trying to upgrade pip version.
It was resolved with the following commands:
python -m ensurepip
The above command restores the pip and below mentioned upgrades it.
python -m pip install --upgrade pip
What solved the issue on my case was go to:
cd C:\Program Files\Python37\Scripts
And run below command:
easy_install.exe pip
Follow steps given in https://michlstechblog.info/blog/python-install-python-with-pip-on-windows-by-the-embeddable-zip-file/. Replace x with version number of Python.
Open the pythonxx.__pth file, located in your python folder.
Edit the contents (e.g. D:\Pythonx.x.x to the following):
D:\Pythonx.x.x
D:\Pythonx.x.x\DLLs
D:\Pythonx.x.x\lib
D:\Pythonx.x.x\lib\plat-win
D:\Pythonx.x.x\lib\site-packages
try to type pip3 instead pip.
also for upgrading pip dont use pip3 in the command
python -m pip install -U pip
maybe it helps
turned out i had 2 versions of python on my laptop
both commands worked for me
python -m ensurepip
py -m ensurepip
both with another installation path
c:\tools\python\lib\site-packages
c:\program files (x86)\microsoft visual studio\shared\python36_64\lib\site-packages
only the first path was in my %PATH% variable
First make sure that python is added in environment variable.
Try checking the version of pip or pip3. Use these commands to check.
For pip:
pip --version
For pip3:
pip3 --version
If you can see any version of pip and still not able to use it, then run the following command.
python -m ensurepip
This ensures the pip in your system.
Running these 2 commands helped me:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
If you wrote
pip install --upgrade pip
and you got
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 20.2.1
Uninstalling pip-20.2.1:
ERROR: Could not install packages due to an EnvironmentError...
then you have uninstalled pip instead install pip.
This could be the reason of your problem.
The Gorodeckij Dimitrij's answer works for me.
python -m ensurepip
I found this post while looking for a solution for the same problem. I was using an embedded python distribution. In this case, the solution is to uncomment import site in the file python<version>._pth.
The ensurepip module was added in version 3.4 and then backported to 2.7.9.
So make sure your Python version is at least 2.7.9 if using Python 2, and at least 3.4 if using Python 3.
I'v solved this error by setting the correct path variables
C:\Users\name\AppData\Local\Programs\Python\Python37\Scripts
C:\Users\name\AppData\Local\Programs\Python\Python37\Lib\site-packages
I was facing same issue and resolved using following steps
1) Go to your paython package and rename "python37._pth" to python37._pth.save
2) curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
3) then run python get-pip.py
4) pip install django
Hope this help
I've solved this error downloading the executable file for python 3.7.
I've had downloaded the embeddeable version and got that error.
Now it works! :D
The method I'm going to tell might not be the correct way to do it. But this method solved my issue. I tried every solution on youtube and StackOverflow methods.
If you have two python versions installed. Delete one. I have the python 3.8.1 and 3.9.0 versions installed. I deleted version 3.9.0 from the C directory.
Now go to the control panel > System and security > System > Advanced system settings.
Click on 'environment variables'.
Select the path and click on 'edit'
Now, add the path of the python and also the path of pip module. In my case it was c:\python38 and c:\python38\scripts
This method solved my issue.
Instead of Python zip install python by python installer. It fixed the issue for me.

How to use pip with multiple instances of python

I recently installed python3 only to realize that mysql-python as well as many other modules were not well supported with it yet. So I changed the path in my bashrc file to point to an installation of python 2.7. The problem is that when I installed python 3 I also installed distribute and pip along with it. I removed the pip and distribute files from the python3 bin directory and installed setuptools and pip using python 2.7 however now when I use the pip command to install django and mysql-python, I get a bash error python331/bin/pip No such file or directory. It's still looking for pip in the python3 install. How can I remedy this?
Thanks
...I get a bash error python331/bin/pip No such file or directory.
It's still looking for pip in the python3 install. How can I remedy
this?
bash, by default, hashes the locations of commands to avoid searching $PATH each time, so if, when you execute...
$ type pip
...you get something like...
pip is hashed (python331/bin/pip)
...you just need to clear the hash table for bash with...
$ hash -r
...then it'll pick up the version in Python 2.7 the next time you try to run pip.
Fixed it.
Renamed the directory of where the python3 was installed, bash automatically looks for the next available python install python 2.7

Categories

Resources