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.
Related
Beginner here. I've just learned the basics of python using VS. I don't know why I get a syntax error in the VSCode text file but not on the terminal for the command.
Any assistance helping me understand would be great, thank you.
Tried to install boto3 with pip.
You cannot run shell commands from a python script.
This is the right way to do it. You can also use the subprocess module to do it.
import os
# In Linux
os.system("python3 -m pip install boto3")
# In Windows
os.system("py -m pip install boto3")
Although, it's not recommended installing packages inside your code.
You can use a requirements.txt file. Then you just need to run this command once in your terminal:
pip install -r requirements.txt
py -m pip install boto3
Obviously, this does not conform to python syntax.
Usually we call it a command line.
We run it in the shell instead of python file.
Python files will be compiled and then run. This command line statement will not be compiled (As the wavy line in the file reminds, this is an error code). You can further learn Python syntax to learn more about this problem.
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.
I wrote my first program with a non built-in module and it works when I run it in pycharm, but when I try to run it in cmd I get an error: app.py, line 1, in <module> from pytube import YouTube ModuleNotFoundError: No module named 'pytube'
I've tried installing pytube module via cmd once again, but the problem still occurs
EDIT: The rest of my scripts are working fine (there are using built-in only modules)
Have you tried installing Pytube with pip on your command prompt? Enter: pip3 install pytube in your terminal and rerun the script. It wasn't clear with the original post if you already did this.
If this doesn't work, try running your script with the -m flag: $ python -m main
A more detailed answer for this issue is already available here.
Did you create an environment when you were in pyCharm? There's a chance you have to activate the env when you are in the cmd prompt.
Console without an environment
C:\path>
Activate environment named 'base'
C:\path>activate base
Console with an environment named 'base'
(base) C:\path>
Ok, so after some research and trying different solutions, I managed to run my script just by copying the missing module to the same directory as my app.py file, I don't know if it's the best solution, but it works.
I am trying to create virtualenvs for my script. When I use pyinstaller without virtualenvs (just sudo pyinstaller myscript.spec) everything works fine. After that I activate virtualenvs and do same thing (pyinstaller myscript.spec) . When I try to execute this two files the standart one (first one) works but the one that I create with virtualenvs gives ImportError: No module named 'sip'. I did not use sip in my script and did not import it anywhere. I do pip3 install sip and compile script again but it did not change anything. What is this error and how can I fix it?
Try sudo apt-get install python-sip to install Ubuntu's version
I'm trying to run this line of code from the beginning of a python script in pycharm:
!pip install pyknow
but it throws an invalid syntax error. In jupyter notebooks this magic command would work, but it seems is not the same here. What's the correct of doing this please?
EDIT
the script where i'm trying to run this command from is a .py file
Thank you very much in advance
You could try something like this:
import os
os.system('pip install pyknow')
This would run the pip install pyknow command in terminal, which is where you would usually put it.
If you have a requirements file, then I think you can run:
import os
os.system('pip install -r requirements.txt')
You should edit the command to
pip install pypi
Because the (pypi) is the name of package (pyknow)
pip is not a python script... it's a bash script.
you can't just run it from a python script...
if you are trying to have a script that will take care of the dependencies I would suggest creating a bash script that would install what it needs then execute the .py script.