1

Aim: Build projectoxford into raspberrypi3 - https://channel9.msdn.com/Blogs/jsturtevant/Setting-up-Project-Oxford-for-Python-on-Windows

At 2:11 of the video, for windows, the command used to create the virtual environment is:

c:\Python3.5\python.exe -m venv env

However, I could not find the python.exe file in raspbian??? No idea this is why; I can only find the python3.5 file with alot of other files. A quick search for python.exe in python3.5 of my raspberry pi3 does not give any results.

A search online have given this solution for Mac:

$ python3.5 -m venv .env

Qn: Can I use this command in replace of c:\Python3.5\python.exe -m venv env ? Would they both give the same results? If not, what should I use instead?

Latest addition: Running the following command give the error:

pi@raspberrypi:~/happy-image-tester-django $ source env/bin/pip install -r requirements.txt
from: can't read /var/mail/pip
bash: env/bin/pip: line 10: syntax error near unexpected token `('
bash: env/bin/pip: line 10: `    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])'

Django module unfound:

pi@raspberrypi:~/happy-image-tester-django $ source env/bin/activate
(env) pi@raspberrypi:~/happy-image-tester-django $ python manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 16, in <module>
    from django.core.management import execute_from_command_line
ImportError: No module named 'django'

(env) pi@raspberrypi:~/happy-image-tester-django $ python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
  File "<string>", line 1
    from distutils.sysconfig import get_python_lib; print get_python_lib()
                                                                       ^
SyntaxError: invalid syntax

1 Answer 1

2

That video is for installing on Windows. Windows uses .exe files as executables; other operating systems don't. Unix-like systems such as Linux and macOS don't generally use extensions in the same way as Windows does to indicate file type, and usually an executable has no extension at all in a Unix-like systems. The history of that is quite complex, but you can read a little more about the differences here.

You should also notice that c:\Python3.5 doesn't exist on your Pi, because that's a Windows path. Once again, different OS, different rules. Probably most important for you when you follow along is that Linux systems use / rather than \ as a separator.

None of the above really matters though, because all that command wants you to do is run Python. As you've correctly identified, you can just run python3.5 to run it on your system.

As I mention above, it looks like you'll just need to do minor adjustments to the commands in the video to get it working on Linux. Since you want to run:

python3.5 -m venv .env

The directory it'll create will be called .env, not env (so replace all instances of env with .env in the steps). On Linux, you'll need to use / as the path separator instead of \. You'll also need to use source .env/bin/activate, not env\Scripts\activate.bat (that's noted in the documentation for venv).

5
  • Thank you so much once more!!! I'm really grateful towards you! By the way, after running python3.5 -m venv .env , I wanted to run the next step which is env\Scripts\pip install -r requirements.txt. However, I'm not even able to find the Scripts file in env of the happy-image-tester folder. Is it like what you have suggested: source .env/bin/pip install -r requirements.txt; but it does not work, the error is edited above. Lastly, am I right to say that all the 'Scripts' files in windows are replaced by 'bin' files instead and to call it we need to include source too? Thanks! @Aurora0001 Commented Jan 15, 2018 at 18:36
  • 1
    Once you've activated your virtualenv, just run pip install <whatever> and python <file.py>; the activation rewrites pip and python to mean your venv's version. You can then deactivate later on, if you need to, with source .env/bin/deactivate. Commented Jan 15, 2018 at 18:50
  • Thank you for such a succinct explanation! I've managed to enter the env and after i entered, I realised that django is module is not found; no idea why this is happening though because I do have django previously in my pi, do i have to re-install django again? The error I've gotten and my attempt to download django is as edited. I'm so sorry, I accidentally edited your reply instead of my post!!! Please kindly reject the edition by me thanks! Commented Jan 15, 2018 at 19:15
  • 1
    @GoodCodes Yep, you'll need to reinstall packages; the idea of a virtual environment in Python is to have a completely isolated setup. As such, any packages you installed with Pip globally (before you setup a venv) will not be available until you install them again. Just run pip install django, and it should work just fine. Commented Jan 15, 2018 at 19:34
  • Ohhh, sure thanks! However, unfortunately, after I installed django and tried to run the python file, I'm faced with patterns not found, and none of the workaround in the internet that I have tried works either :( I have posted it in another post : raspberrypi.stackexchange.com/questions/77834/… , do give it a look if possible pleaseeeee, thankyou so much for all your help!!! @Aurora0001 Commented Jan 16, 2018 at 5:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.